Adding style to model (paperclip)

hello,

I have a model (item) with one attachment (photo) and one style (small):

class Producto < ActiveRecord::Base
  has_attached_file :photo, :styles => { :small => "50x50"},
end

I would like to add a new style (:large), so I modify item.rb:

class Producto < ActiveRecord::Base
  has_attached_file :photo, :styles => {{ :small => "50x50"},{ :large =>
"150x150"}}
end

it seems to be ok, but when I submit in edit or new views, I get the
following error:

NoMethodError (undefined method `[]' for nil:NilClass):
  app/controllers/admin/items_controller.rb:64:in `update'
  app/controllers/admin/items_controller.rb:63:in `update'

Controller code:
  def update
    @item = Item.find(params[:id])
    respond_to do |format|
      if @item.update_attributes(params[:item])
        format.html { redirect_to(admin_items_path, :notice => 'OK') }
      else
        format.html { render :action => "edit" }
      end
    end
  end

If I remove the new style (:large) in item.rb everything works fine
again...

Could someone help me?

Thanks

Not sure, but have you tried using the syntax from the docs,
particularly the last example?

https://github.com/thoughtbot/paperclip/wiki/Usage

I wonder if yours is valid Ruby but invalid has_attached_file syntax.

I changed the following according with documentation:

  has_attached_file :photo, :styles => {
                       :small => {:geometry => '50x50#'},
                       :large => {:geometry => '150x150#'}
                       }

And it works! Using syntax from the docs seems to be a very good idea!

:slight_smile:

Thanks