I am trying to call image tag in a model and return the image if it exists other wise return null like this :-
def medium_avatar_exists?
if self.avatar.present?
image_tag self.avatar.thumb_medium_url
else
image_tag "missing-avatar-medium.png"
end
end
when I call this method from the view :- current_user.medium_avatar_exist?
I get an error saying undefined method image_tag what could be the issue ?
You can’t use helper methods in model
image_tagis an helper method and you are trying to use it in the model hence it gives an error.Try following instead in your
application_helper.rbor some other helpr you wantOR Just