简体   繁体   中英

ruby 1.9.2 lambda with paperclip

I am upgrading my working app to 1.9.2 but can't find the answer to the following :

I create a Asset like so in my controller :

@asset = Asset.new(params)

and then in my model use a lambda to dynamically generate the styles like so :

has_attached_file :asset,
  :styles => lambda { |attachment| attachment.instance.choose_styles}

Then i check a certain value that was in my params like so:

def choose_styles
  if self.item_name == 'Car'
    { :small => ["200x200>"], :medium => ["400x400>"], :large => ["700x700>"], :full_screen => ["1000x700>"] }
  else
    ........
 end

The problem is item_name is nil in 1.9.2 till after this has been run then seems to be set from params. This all works switching back to 1.8.7

Is the something anyone can see to help me please ??

thank rick

I know this is not an answer that fits with your question. By the way, you can switch to carrierwave ( https://github.com/jnicklas/carrierwave ). You can choose formats in a more granular way creating various versions and nesting them.

As an example, an ipothetic AssetUploader could be:

...
version :thumb_200x200 do
  process :resize_to_fill => [200,200]
end

version :big_600x600 do
  ...
end
...
version :car, :if => in_category(:car)?
  version :thumb_200x200
  version :another_etc
end
...
protected
  def in_category?(name)
    model.item_name.downcase == name.to_s
  end
...

this is just an example of code, adjust for your needs ;)

cheers, A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM