I would like to change where the logo in my app links to based on the users status (logged in or not).
If the user is logged in I would like it to link to their profile page (users/show). If not logged in then to root_path.
I have this setup using a helper:
View:
<%= link_to logo, root_path %>
Helper:
def logo
logo = image_tag("rlogo.png", alt: "Sample App")
end
Thanks
The ternary solution Matzi suggested would certainly work, but another option would be to modify your helper to set up the logo and link, something like this (where
current_useris a method that returns aUserinstance for the logged in user):Then, in your view, just include
You could also use your existing
logohelper inside thelogo_linkhelper, if it’s something you’ll still want outside to use of that context.