ruby 1.9.2 lambda 带回形针
我正在将我的工作应用程序升级到 1.9.2,但找不到以下问题的答案:
我在控制器中创建一个像这样的资产:
@asset = Asset.new(params)
然后在我的模型中使用 lambda 动态生成这样的样式:
has_attached_file :asset,
:styles => lambda { |attachment| attachment.instance.choose_styles}
然后我检查我的参数中的某个值如下所示:
def choose_styles
if self.item_name == 'Car'
{ :small => ["200x200>"], :medium => ["400x400>"], :large => ["700x700>"], :full_screen => ["1000x700>"] }
else
........
end
问题是 item_name 在 1.9.2 中为 nil ,直到运行之后似乎是从参数设置的。这一切都可以切换回 1.8.7
任何人都可以看到来帮助我吗?
感谢 里克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这个答案不适合你的问题。顺便说一句,您可以切换到 Carrierwave (https://github.com/jnicklas/rierwave)。您可以更精细地选择格式,创建各种版本并嵌套它们。
举个例子,一个假想的 AssetUploader 可以是:
这只是一个代码示例,根据您的需要进行调整;)
干杯,
一个。
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:
this is just an example of code, adjust for your needs ;)
cheers,
A.