Undefined method `has_attached_file' with paperclip 2.3.8 gem for Rails 2 using Ruby 1.8.7

狂风中的少年 提交于 2019-12-01 23:07:36

Ok, firstly, just to cover the "obvious" base: do "ls vendor/plugins" just to make sure that some version of paperclip is actually in your plugins directory and is therefore reachable by your application.

Secondly - the "require paperclip" in the model seems wrong to me. I'm guessing that require should go in your environment instead. Try putting it at the end of config/environments.rb instead.

Thirdly (and maybe unrelated to your specific problem) - 2.0.2 is a really old version of rails. If you can I'd upgrade to 2.3.5, or at the very least, 2.2.x. For all we know - you could have a problem because you've got a new version of paperclip and an old version of rails... this does sometimes make a difference.

A lot of the other links you posted are referring to installations up to Rails3 - the solutions to their problems will be different to yours for that reason.

Slightly related, decided to put this here for future googlers.

Using Rails 2.3.14 on Ruby 1.8.7 with bundler. As suggested by thoughtbot I'm using paperclip 2.7, i.e. my gemfile contains:

gem "paperclip", "~> 2.7.0"

I was also receiving the "undefined method" error. What fixed it for me was to drop a paperclip.rbfile into config/initializerscontaining the following:

require "paperclip/railtie"
Paperclip::Railtie.insert

Hopefully this will save someone a bit of headache.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!