2
votes

This function is defined in the application_help.rb:

  def gravatar_url_for(email, options = {})

    url_for(
      {
        :protocol => 'http://',
        :host => 'www.gravatar.com',
        :controller => 'avatar',
          # :controller => 'avatar.php',
        :gravatar_id => Digest::MD5.hexdigest(email),
        :only_path => false
      }.merge(options)
    )

  end

It's used in views:

<%= image_tag(gravatar_url_for user.email, {:d => 'identicon', :s => 32, :r => 'g'}) %>

Occasionally, its usage will result in a routing error:

No route matches {:controller=>"avatar", :d=>"identicon", :r=>"g", :gravatar_id=>"486575e581db04b7c8ca218af8488657", :s=>32}

A valid email is being supplied when the error occurs.

If I replace the url_for() with this logic, it works as expected:

url_for("http://www.gravatar.com/avatar/" + Digest::MD5.hexdigest(email) + "?d=identicon&s=40&r=g")

** edit ** I had removed the following line from the routes.rb file:

# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
match ':controller(/:action(/:id(.:format)))'

Is there a way to get the url_for to work without the 'legacy wild controller route'?

1

1 Answers

0
votes

You might want to take a look at the Gravtastic plugin for Rails which supports Gravatar images in both Ruby and JavaScript.