locoboy
locoboy

Reputation: 38940

helper method not accessible in view

I have the following code in my view:

<%= gravatar_for @user %>

and the following code in my helper:

module UsersHelper
    def gravatar_for(user)
        gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
        gravatar_url = "http://gravatar.com/avatar#{gravatar_id}.png"
        image_tag(gravatar_url, alt: user.first_name.to_s + user.last_name.to_s, class: gravatar)
    end

end

However I'm getting an error: undefined local variable or methodgravatar' for #<#:0x00000100a1cbf0>`

What could be causing this?

Upvotes: 0

Views: 410

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

You're using a reference, gravatar, in the call to image_tag.

If you mean to apply a style, use a string, "gravatar". Otherwise you need to make sure the method or value gravatar exists/is initialized, and available.

Upvotes: 4

Related Questions