上传到S3在Heroku上使用回形针(delayed_job的问题) [英] Uploading to S3 on Heroku with Paperclip (delayed_job question)
问题描述
我想上传到投资程序,我已经建立,特别是努力寻找到挂钩的delayed_job到进程。它所有的工作,否则。现在它返回未定义的方法'呼吁'的#<类别:0xae68750>
在应用程序/控制器/ portfolio_items_controller.rb:18:在创建
所以这里是我的模型和部分控制器...任何人看到任何可以去错了吗?我使用的是现在的钩子我从这个博客了: HTTP://madeof$c$c.com/posts/42-paperclip-s3-delayed-job-in-rails
I'm trying to upload to a portfolio app I've built, specifically trying to find where to hook delayed_job into the process. It all works otherwise. Right now it returns undefined method 'call' for #<Class:0xae68750>
on app/controllers/portfolio_items_controller.rb:18:in 'create'
so here's my model and that portion of the controller... anyone see anything that could be going wrong? The hook I'm using now I got from this blog: http://madeofcode.com/posts/42-paperclip-s3-delayed-job-in-rails
/app/controllers/portfolio_items_controller.rb
/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
/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
编辑:感谢善良的人,这不是失踪。新了。但现在它的before_source_post_process没有定义?我不能找到方法中的任何位置,但该博客文章,这太问题。是不是有什么比较合适?
thanks to kind people, it's not the missing .new anymore. But now it's that the before_source_post_process is not defined? And I can't find that method in anywhere but that blog post and this SO question. Is there something more appropriate?
推荐答案
我觉得这样的:
@portfolio_item = PortfolioItem.(params[:portfolio_item])
应该最有可能是这样的:
should most likely be this:
@portfolio_item = PortfolioItem.new(params[:portfolio_item])
这篇关于上传到S3在Heroku上使用回形针(delayed_job的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!