【发布时间】:2014-03-07 21:39:49
【问题描述】:
我正在通过Michael Hartl's Ruby on Rails 教程向用户个人资料添加 Gravatar 图像。
这是我的代码:
#app/views/users/show.html.erb
<% provide(:title, @user.name) %>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
还有帮手:
#app/helpers/users_helper.rb
module UsersHelper
# Returns the Gravatar (http://gravatar.com/) for the given user.
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
然后我使用 update_attributes 来更新数据库中的用户:
$ rails console
>> user = User.first
>> user.update_attributes(name: "Example User",
?> email: "user@myapplication.com",
?> password: "password",
?> password_confirmation: "password")
=> true
所以在那之后当我访问用户个人资料的显示页面时,我只有原始的 gravatar 图片,但没有与用户电子邮件关联的自定义 gravatar。
有什么问题吗?
谢谢,
【问题讨论】:
-
电子邮件
user@myapplication.com是否有gravatar.com 的帐户?如果是新帐户,则需要几分钟才能完成。 -
不,这只是一个例子,我使用了我的真实电子邮件地址,在 gravatar 上有一张自定义照片...
标签: ruby-on-rails devise profile gravatar