【问题标题】:NameError in Users#show用户中的名称错误#show
【发布时间】:2016-09-20 02:39:02
【问题描述】:

显示 /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。有人能帮助我吗?谢谢。

【问题讨论】:

  • 我在下面添加了答案。

标签: mysql ruby-on-rails passenger production


【解决方案1】:

您应该将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]}"

【讨论】:

    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多