我正在尝试上传到我构建的投资组合应用程序,特别是试图找到将delayed_job挂钩到进程的位置。一切都是有效的。现在它在undefined method 'call' for #<Class:0xae68750>
上返回app/controllers/portfolio_items_controller.rb:18:in 'create'
所以这是我的模型和控制器的那部分......任何人都可以看到任何可能出错的地方?我现在使用的钩子是我从这个博客得到的:http://madeofcode.com/posts/42-paperclip-s3-delayed-job-in-rails
/app/controllers/portfolio_items_controller.rb
def create
@portfolio_item = PortfolioItem.new(params[:portfolio_item])
if @portfolio_item.save
flash[:notice] = "Portfolio item created. As soon as files are uploaded Portfolio item will be made live."
redirect_to @portfolio_item
else
render :action => 'new'
end
end
/app/models/asset.rb
class Asset < ActiveRecord::Base
attr_accessible :image, :image_file_name, :image_content_type, :image_file_size, :portfolio_item_id, :order
belongs_to :portfolio_item
has_attached_file :image,
:styles => {
:thumb => "20x20#",
:small => "100x100",
:large => "600x600>"
},
:storage => :s3,
:s3_credentials => {
:access_key_id => ENV["S3_KEY"],
:secret_access_key => ENV["S3_SECRET"]
},
:bucket => ENV["S3_BUCKET"],
:path => "portfolio/:attachment/:id/:style/:basename.:extension"
before_source_post_process do |image|
if source_changed?
processing = true
false
end
end
after_save do |image|
if image.source_changed?
Delayed::Job.enqueue ImageJob.new(image.id)
end
end
def regenerate_styles!
self.source.reprocess!
self.processing = false
self.save(false)
end
def source_changed?
self.source_file_size_changed? ||
self.source_file_name_changed? ||
self.source_content_type_changed? ||
self.source_update_at_changed?
end
end
class ImageJob < Struct.new(:image_id)
def perform
Image.find(self.image_id).regenerate_styles!
end
end
编辑:感谢善良的人们,不再是失踪的.new了。但现在是没有定义before_source_post_process?除了那篇博文和这个问题,我无法在任何地方找到这种方法。有什么更合适的吗?
答案 0 :(得分:4)
before_source_post_process不适合你。它仅适用于:
has_attached_file :source
在你的情况下它应该是
before_image_post_process
同样,source_changed?方法应该是:
def source_changed?
self.image_file_size_changed? ||
self.image_file_name_changed? ||
self.image_content_type_changed? ||
self.image_update_at_changed?
end
答案 1 :(得分:2)
我想这个:
@portfolio_item = PortfolioItem.(params[:portfolio_item])
最有可能是这样的:
@portfolio_item = PortfolioItem.new(params[:portfolio_item])