I want to do a conditional link_to
which is displayed only if the user is logged in as an admin. So I did this :
Application Controller
def confirm_admin
if session[:role] == "admin"
@isAdmin = true
else
flash[:notice] = "Vous n'avez pas les droits pour accéder à cette page."
redirect_to root_path
return false
end
end
View
<%= link_to_if is_admin, 'Editer l\'idée', edit_idee_path(@idee), :class => "editer custom-button" %>
The link disappeared but the text is still present, do you have any idea why ?
link_to_if
only makes the text no-link text; it removes the link from the text, not the text itself.What you are trying to do, you can achieve it through following code: