我有一個問題:未定義的helper方法
undefined method `avatar_url' for #<User:0x000000040783a8>
控制器:
class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
helper_method :avatar_url
protected
def avatar_url(user)
if user.avatar_url.present?
user.avatar_url
else
default_url = "#{root_url}images/guest.png"
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=48&d=#{CGI.escape(default_url)}"
end
end
end
鑑於:
...
<%for user in @users %>
<%= image_tag avatar_url(user) %>, username: <%= user.username %>, e-mail: <%= user.email %>
<% end %>
...
有人幫幫我嗎?
在用戶類中是否有'avatar_url'方法?錯誤來自對user.avatar_url的調用,而不是應用程序幫助方法本身。 –
建議的Thx,我會檢查它。 – justi