ruby 1.9.2 lambda 带回形针

发布于 2024-11-07 02:33:40 字数 651 浏览 0 评论 0原文

我正在将我的工作应用程序升级到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守不住的情 2024-11-14 02:33:40

我知道这个答案不适合你的问题。顺便说一句,您可以切换到 Carrierwave (https://github.com/jnicklas/rierwave)。您可以更精细地选择格式,创建各种版本并嵌套它们。

举个例子,一个假想的 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
...

这只是一个代码示例,根据您的需要进行调整;)

干杯,
一个。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文