我找到了这个教程(http://www.coffeepowered.net/2009/02/15/graceful-degredation-using-gravatar-as-a-fallback-avatar-with-paperclip/),它是关于将gravatar实现为启用回形针的模型的默认图像,但在实现时,我看到了消息"undefined method ` `match‘for :format,:png:Array“。这篇文章有什么问题吗?
发布于 2009-10-23 11:10:34
我已经更新了代码,使您更容易理解和调试。
Paperclip.interpolates(:gravatar_url) do |attachment, style|
size = nil
# style should be :tiny, :small, or :regular
# size_data is assumed to be "16x16#", "20x20#", or "25x25#", i.e., a string
size_data = attachment.styles[style][:geometry]
if size_data
# get the width of the attachment in pixels
if thumb_size = size_data.match(/\d+/).to_a.first
size = thumb_size.to_i
end
end
# obtain the url from the model
# replace nil with "identicon", "monsterid", or "wavatar" as desired
# personally I would reorder the parameters so that size is first
# and default is second
attachment.instance.gravatar_url(nil, size)
end发布于 2010-01-01 00:46:36
请注意,我在尝试此解决方案时遇到以下错误:
NoMethodError: undefined method `first' for #<Hash:0xb6476178>
from /home/bob/dev/Firehoze/app/models/user.rb:114:in `gravatar_url'我通过替换这行代码解决了这个问题:
size_data = attachment.styles[style].first使用
size_data = attachment.styles[style][:geometry]发布于 2013-12-29 02:17:26
Paperclip.interpolates :gravatar_url do |attachment, style|
attachment.instance.gravatar_url(attachment.styles[style][:geometry].split('x').first)
endhttps://stackoverflow.com/questions/1610331
复制相似问题