简体   繁体   中英

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 method gravatar' for #<#:0x00000100a1cbf0>`

What could be causing this?

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.

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