0

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.

Yo Ludke
  • 2,149
  • 2
  • 23
  • 38
  • What do you have in the `line 74` of your `User` model? – Pavan Jun 09 '14 at 07:52
  • @Pavan sorry, forgot to include it - it's the `has_attached_file` call for Paperclip – Yo Ludke Jun 09 '14 at 07:54
  • Do you have a `photo` attribute in your `users` table? – Pavan Jun 09 '14 at 07:56
  • The application works in development, production and staging. It's only the rake task who cannot load the user model. I have photo_file_name character varying(255), photo_content_type character varying(255), photo_file_size integer, photo_updated_at timestamp without time zone, in the user table (using postgres, copied from current structure.sql) – Yo Ludke Jun 09 '14 at 07:59
  • it's not finding your Class type, so a includes/require is missing. The clue is here `#`. Without seeing more code I cannot tell you exactly why. – Rots Jun 09 '14 at 08:23
  • The assets.rake Task file `require "logger" Thread.abort_on_exception = true #namespace :anything_you_want do namespace :assets do end #end` If I remove the comments on anything_you_want it works – Yo Ludke Jun 09 '14 at 08:29
  • Any way why this would help? Maybe the namespace assets is already taken and shouldn't be used? – Yo Ludke Jun 09 '14 at 08:41

1 Answers1

0

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 :)

Yo Ludke
  • 2,149
  • 2
  • 23
  • 38