Answer the question
In order to leave comments, you need to log in
How to make user_helper correctly?
I want to make a helper for avatars, but even it doesn’t work
. In general, what we have:
module UsersHelper
def avatar_for(user, options = { size: 50 })
if user.nil? or user.avatar.nil?
image_tag('/uploads/1.png', :size => 50)
size = options[:size]
else
image_tag(user.avatar.thumb, :size => 52)
size = options[:size]
end
end
end
<%= avatar_for @user %>
Answer the question
In order to leave comments, you need to log in
The task is clear, but it looks like this:
module UsersHelper
def avatar_for(user, options = { size: 50 })
if user.try(:avatar).blank?
image_tag('/uploads/1.png', :size => options[:size])
else
image_tag(user.avatar.thumb, :size => options[:size])
end
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question