简体   繁体   中英

NameError in Users#show

Showing /home/bdme551/bdme21/app/views/users/show.html.erb where line #6 raised:

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

I'm getting the NameError . Can someone help me, please? Thanks.

You should call size with to options[:size] because you are passing hash on options parameter.

Instead of:

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

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM