0
module UsersHelper

  # Returns the Gravatar (http://gravatar.com/) for the given user.
  def gravatar_for(user, options = { size: 10 })
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    size = options[:size]
    gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  end
end

我已经使用了这段代码,并假设它会改变 gravatar 的大小,但它似乎对它没有影响?我错过了什么吗?我还尝试将视图中的值更改为:

<%= gravatar_for @user, size: 10 %>
<%= @user.name %>

看看这是否改变了什么,无济于事。

4

1 回答 1

1

假设您的帮助模块如下

module UsersHelper

   # Returns the Gravatar (http://gravatar.com/) for the given user.
  def gravatar_for(user, options = { size: 50 })

    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)

    size = options[:size]

    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"

    image_tag(gravatar_url, alt: user.name, class: "gravatar")

  end

end

然后在视图中传递您的尺寸

<%= gravatar_for @user, :size => 30 %>
于 2014-06-26T19:12:37.870 回答