Last Updated on November 30, 2019 by Christopher G Mendla
There can be times when you want to show a field, or do some other action, only for a certain controller action such as ‘new’.
In this example, we have a form and we want to the currently logged in user (@current_user_name in this case) if this is a new complaint. However if we are editing we want to show the name of the user in the user table (@user.name)
<% if action_name = ‘new’ then %> <%= @current_user.name %><% else %> <%= @user.name %><% end %>