종이 클립 + 그라바타
-
05-07-2019 - |
문제
이 튜토리얼을 찾았습니다 (http://www.coffeepowered.net/2009/02/15/graceful-degredation-using-gravatar-as-a-fallback-avatar-with-paperclip/) Gravatar를 기본 클립 지원 모델에 기본 이미지로 구현하는 것에 대해, 그러나 구현시 [: format, : png] : array "에 대한"정의되지 않은 메소드 'match'를 참조하십시오. 이 기사에서 무엇이 잘못 되었습니까?
해결책
더 쉽게 이해하고 디버그 할 수 있도록 코드를 업데이트했습니다.
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
다른 팁
참고이 솔루션을 시도 할 때 다음과 같은 오류가 발생했습니다.
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]
Paperclip.interpolates :gravatar_url do |attachment, style|
attachment.instance.gravatar_url(attachment.styles[style][:geometry].split('x').first)
end
계속 문제가 있다면 시도해 볼 수 있습니다. 화신 종이 클립과 그라바타를 포함하여 다양한 아바타 방법의 체인을 지원하는 GEM.
NB : 내가 그 일을 썼기 때문에 이것은 약간 뻔뻔한 플러그입니다.
제휴하지 않습니다 StackOverflow