gpt4 book ai didi

ruby-on-rails - 使用 Paperclip 上传到 Heroku 上的 S3(delayed_job 问题)

转载 作者:行者123 更新时间:2023-12-02 07:50:37 25 4
gpt4 key购买 nike

我正在尝试上传到我构建的投资组合应用程序,特别是试图找到将 delayed_job Hook 到流程中的位置。否则一切正常。现在它返回 undefined method 'call' for #<Class:0xae68750>app/controllers/portfolio_items_controller.rb:18:in 'create'所以这是我的模型和 Controller 的那部分……有人看到任何可能出错的地方吗?我现在使用的钩子(Hook)是从这个博客获得的: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?除了那篇博文和这个 SO 问题,我在任何地方都找不到那个方法。有没有更合适的?

最佳答案

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

关于ruby-on-rails - 使用 Paperclip 上传到 Heroku 上的 S3(delayed_job 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4054108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com