How to add gravatar / identicons to Ruby on Rails?

I looked through the following, but they are not clear, especially the links to the dependencies of DataMapper and gem.

All I want as a result is to get my @ user.email value, which is in | do | loop and gravitational display, where the identifier is set to "y" - in other words, these cute, seemingly random patterns!

But when I look at what is available, it’s not clear what to do - especially the links to the dependencies of DataMapper and gem.

http://github.com/chrislloyd/gravtastic/tree/master

I play with this, but I wanted to get feedback from others before diving too deep!

http://www.thechrisoshow.com/2008/10/27/adding-gravatars-to-your-rails-apps

I installed the plugin for tree plugins:

http://github.com/woods/gravatar-plugin/tree/master , which matches the one below ... however, I get an error message when I type:

<%= gravatar_for @user %>

Mistake:

undefined method `gravatar_for' for #<ActionView::Base:0x474ddf4>
+5
source share
5 answers

There is a Gravatar Rails plugin, which can be found here:

http://gravatarplugin.rubyforge.org/

Install the plugin as follows:

  ruby script/plugin install svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar

After installing the plugin, if your model meets the "email" method, this tag will show Gravatar:

  <%= gravatar_for @user %>
+1
source

Put this code in your ApplicationHelper so that it gravatar_foris available in all views.

def gravatar_for email, options = {}
    options = {:alt => 'avatar', :class => 'avatar', :size => 80}.merge! options
    id = Digest::MD5::hexdigest email.strip.downcase
    url = 'http://www.gravatar.com/avatar/' + id + '.jpg?s=' + options[:size].to_s
    options.delete :size
    image_tag url, options
end

In the views:

<%= gravatar_for 'my@mail' %>
<%= gravatar_for 'my@mail', :size => 48 %>
<%= gravatar_for 'my@mail', :size => 32, :class => 'img-class', :alt => 'me' %>

. Gravatar, . , , require 'digest' ( Rails 3).

+13

, :

Sam152, MD5 , GET gravatar.

MD5 - , ActionPack ( ActionView). "config/environment.rb" :

require 'digest'

, gravatar:

image_tag("http://www.gravatar.com/avatar.php?gravatar_id=#{Digest::MD5::hexdigest(@user.email)}", :alt => 'Avatar', :class => 'avatar')

, , , , gravatar.

+8

MD5 hash , URL- gravatar. URL- . , .

http://www.gravatar.com/avatar/  md5(email)  ?s=128&d=identicon&r=PG

, , MD5 . .

+1

https://github.com/sinisterchipmunk/gravatar , , .

:

Gravatar.new(email).image_url

, wavatar

Gravatar.new(email).image_url + '?d=wavatar'
+1

All Articles