gpt4 book ai didi

ruby-on-rails - 回形针+头像

转载 作者:太空宇宙 更新时间:2023-11-03 17:41:40 26 4
gpt4 key购买 nike

我发现这个教程 (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” .这篇文章有什么问题吗?

最佳答案

我更新了代码,使您更容易理解和调试。

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

关于ruby-on-rails - 回形针+头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1610331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com