Search code examples
mysqlruby-on-railspassengerproduction

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.


Solution

  • 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]}"