我查看了以下内容,但不清楚,尤其是对 DataMapper 和 gem 依赖项的引用。
我想要的结果就是能够获取我在 |do| 中的 @user.email 值。循环并显示一个头像,其中标识设置为“y”——换句话说,那些看似随意的可爱图画!
但是当我查看可用的内容时,并不清楚该做什么——尤其是对 DataMapper 和 gem 依赖项的引用。
http://github.com/chrislloyd/gravtastic/tree/master
我正在玩这个,但我想在潜入太深之前从其他人那里得到反馈!
http://www.thechrisoshow.com/2008/10/27/adding-gravatars-to-your-rails-apps
我安装了 woods gravatar 插件:
http://github.com/woods/gravatar-plugin/tree/master这与下面提到的相同......但是,当我输入时出现错误:
<%= gravatar_for @user %>
错误是:
undefined method `gravatar_for' for #<ActionView::Base:0x474ddf4>
最佳答案
将此代码放在您的 ApplicationHelper 中,以便 gravatar_for
在所有 View 中都可用。
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
在 View 中:
<%= gravatar_for 'my@mail' %>
<%= gravatar_for 'my@mail', :size => 48 %>
<%= gravatar_for 'my@mail', :size => 32, :class => 'img-class', :alt => 'me' %>
我完善了slant的解决方案。关注 Gravatar guidelines , 电子邮件应在散列之前修剪和小写。还有,好像
require 'digest'
不需要(在 Rails 3 上测试)。
关于ruby-on-rails - 如何将 gravatar/identicons 添加到 Ruby on Rails 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/770876/