Mark Soden
Mark Soden

Reputation: 81

rails condition one line

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

Answers (1)

apneadiving
apneadiving

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

Related Questions