views:

51

answers:

2

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

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

Edit: 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?

+1  A: 

I think this:

 @portfolio_item = PortfolioItem.(params[:portfolio_item])

should most likely be this:

 @portfolio_item = PortfolioItem.new(params[:portfolio_item])
Brett Bender
Oh dear. Yes, that's it. It still doesn't work. I've edited the question.
Reactor5