I want to create helper that return the avatar linked to the user.
for that i do:
<%= basic_avatar(user)%>
and the helper:
def basic_avatar(user)
link_to image_tag(user.avatar) ,'#', :title => user.name
end
But now, i want to add some options like attributes, classes etc.
for example, i want to do this:
<%= basic_avatar(user, class: 'avatar')%>
or:
<%= basic_avatar(user, class: 'avatar', name: 'avatar')%>
Just add an options hash to helper declaration, and use that when making your image tag. The last argument in the image_tag call is a hash, so you’re basically all set.
This makes it so the options is optional, and then they just get passed along to
image_tag, as well as the title you want.