In a rake task for production to migrate some assets I want to require a model that uses Paperclip. But I get the error
NoMethodError: undefined method `has_attached_file' for #<Class:0x00000006c12680>
~/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.18/lib/active_recor/dynamic_matchers.rb:55:in `method_missing'
/app/models/user.rb:74:in `<class:User>'
Line 74 declares the attachment:
has_attached_file :photo, styles: { original: '1024x1024>', s64: ["64x64#", "jpg"] },
:convert_options => { original: "-quality 85 -strip", s64: "-quality 85 -strip" },
processors: [:trimmer, :cropper], url: '/system/product/:attachment/:id/:style/:filename',
path: ':rails_root/public/system/product/:attachment/:id/:style/:filename'
from the Rakefile: lib/task/asset.rake
task :preload => :environment do
require 'user'
end
I tried to require 'paperclip'
before 'user', but it didn't help.
The problem seemed to have beeen the unfourtune choice of namespace "assets", which seems to interfere with rails defining this namespace already. For anyone who ends here with a similiar question: Try changing the namespace to something unique and see if the error disappears :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.