How to add Gravatar to the user in Ruby on Rails

HI…to all today i learnt how to set Gravator to the user.. Lets create a rails project like this.. $ rails new gravator

$ cd gravator

now create a scaffold for the gravator by

$ rails g scaffold users avator email:text

now migrate db and run server

$ rake db:create

$ rails s 

now open browser and add few users localhost:3000/users

now we have to add gravatar to the user..

open app/helper/application_helper.rb

module ApplicationHelper
  def avatar_url(user)
    gravatar_id = Digest::MD5::hexdigest(user.email).downcase
    "http://gravatar.com/avatar/#{gravatar_id}.png"
  end
end

apps/views/users/index.htnl.erb

<% @users.each do |user| %>
<%= image_tag avatar_url(user) %>
<%= user.email %><%= link_to 'Show', user %><%= link_to 'Edit', edit_user_path(user) %><%= link_to 'Destroy', user, :method => :delete, :data => { :confirm => 'Are you sure?' } %>
<% end %>

Now run the server by rails s

output:

Thats it…now we added gravatar to the user…Thanks …

Author: Balaji

Hi..My name is Balaji and i am working as a Senior Software Developer in India. I am interested in Shell scripts, python, erlang , linux kernel .

6 thoughts on “How to add Gravatar to the user in Ruby on Rails”

  1. I will immediately grab your rss feed as I can not find your email subscription link or enewsletter service. Do you have any? Kindly let me know so that I could subscribe. Thanks. bfccdbfafbbffggb

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: