[英]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>` 但是我遇到一个错误:#<#:0x00000100a1cbf0>`的
undefined local variable or method
gravatar'
What could be causing this? 是什么原因造成的?
You're using a reference, gravatar
, in the call to image_tag
. 您在对
image_tag
的调用中使用了引用gravatar
。
If you mean to apply a style, use a string, "gravatar"
. 如果要应用样式,请使用字符串
"gravatar"
。 Otherwise you need to make sure the method or value gravatar
exists/is initialized, and available. 否则,您需要确定方法或值
gravatar
存在/已初始化且可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.