简体   繁体   English

红宝石1.9.2 lambda用回形针

[英]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 : 我正在将我的工作应用程序升级到1.9.2但无法找到以下答案:

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 : 然后在我的模型中使用lambda动态生成样式,如下所示:

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. 问题是在1.9.2之前,item_name是nil,直到运行之后,似乎是从params设置的。 This all works switching back to 1.8.7 这一切都可以切换回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 ). 顺便说一句,您可以切换到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: 例如,ipothetic AssetUploader可以是:

...
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. 欢呼声,A.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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