Reputation: 81
I want to combine this else if statement into 1 line My code below displays a partial but only if the current URL is not one of the 3 listed in the elsif statement
<% if request.path == landing_path then %>
<% elsif request.path == new_company_path then %>
<% elsif request.path == edit_user_path(current_user.id) then %>
<% else %>
<%= render 'dashboard/user_controls'%>
<% end %>
I'm trying
<% if request.path != (landing_path || new_company_path || edit_user_path(current_user.id) ) then %>
<%= render 'dashboard/user_controls'%>
<% end %>
what am I doing wrong?
Thanks
Upvotes: 0
Views: 473
Reputation: 115511
This will work:
<%= render 'dashboard/user_controls' if [landing_path, new_company_path, edit_user_path(current_user)].all? {|path| request.path != path } )%>
But you'd rather abstract this in a helper.
Upvotes: 2