开发者

How do you fix this Ruby on Rails and Gravatar gem bug?

开发者 https://www.devze.com 2023-03-11 05:17 出处:网络
I\'m trying to use the gravatar_image_tag RoR plug-in and it is giving me this error, when I start up the rails console or the rails server. What do I do to fix it?

I'm trying to use the gravatar_image_tag RoR plug-in and it is giving me this error, when I start up the rails console or the rails server. What do I do to fix it?

/Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb:66: uninitialized constant ActionView::Helpers::AssetTagHelper::AssetPaths::Mutex (NameError)
    from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helper.rb:3:in `require'
    from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helper.rb:3
    from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers.rb:39
    from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/base.rb:134
    from /Library/Ruby/Gem开发者_如何学Cs/1.8/gems/gravatar_image_tag-1.0.0/lib/gravatar_image_tag.rb:97
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler.rb:120:in `require'
    from /Users/pickhardt/projects/sample_app/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51
    from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48:in `tap'
    from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48
    from script/rails:6:in `require'
    from script/rails:6


It's possible your plugin isn't compatible with your version of rails. Gravatar images aren't that hard to do with out a plugin. Here is a solution by Ryan Bates for Gravatars

application_helper.rb

def avatar_url(user)
  if user.avatar_url.present?
    user.avatar_url
  else
    default_url = "#{root_url}images/guest.png"
    gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
    "http://gravatar.com/avatar/#{gravatar_id}.png?s=48&d=#{CGI.escape(default_url)}"
  end
end

users/index.html.erb

<%= image_tag avatar_url(user) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号