用户#show中的NameError

时间:2016-09-20 02:39:02

标签: mysql ruby-on-rails passenger production

显示 /home/bdme551/bdme21/app/views/users/show.html.erb 第6行:

undefined local variable or method `size' for #<#<Class:0x007fb271759100>:0x00000003b579a0>
Extracted source (around line #5):

      def gravatar_for(user, options = { size: 80 })
        gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
        gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
        image_tag(gravatar_url, alt: user.name, class: "gravatar")
      end
    end

我得到了NameError。有谁可以帮助我吗?感谢。

1 个答案:

答案 0 :(得分:0)

您应该sizeoptions[:size]联系,因为您要在options参数上传递哈希值。

而不是:

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

尝试:

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