Adding style to model (paperclip)


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

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

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 =>

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') }
        format.html { render :action => "edit" }

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

Could someone help me?


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

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!