Search code examples
ruby-on-railspathlink-to

How can I display the link only if I'm not already on taht page?


I'm using Rails 4.2.7. I have this link in the header of my application

<%= link_to 'Edit', edit_users_path %>

How would I not render this link if I'm already on the edit_users_path page?


Solution

  • You can put the condition at the end of the erb fragment

    <%= link_to('Edit', edit_users_path) unless current_page? %>