简体   繁体   English

Rake Task不会使用回形针加载模型

[英]Rake Task doesn't load Model with Paperclip

In a rake task for production to migrate some assets I want to require a model that uses Paperclip. 在生产的rake任务中,要迁移某些资产,我需要一个使用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: 第74行声明了附件:

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 从Rakefile:lib / task / asset.rake

task :preload => :environment do
   require 'user'
end

I tried to require 'paperclip' before 'user', but it didn't help. 我试图在“用户”之前require 'paperclip' ”,但这没有帮助。

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 :) 对于任何在此处遇到类似问题的人:尝试将名称空间更改为唯一的名称,然后查看错误是否消失:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM