0

I have nested routes in my routes.rb

resources :companies do
  resources :employees
  resources :accounts
end

In top menu I want to show a certain link when user is in company's controller or in nested controllers (employees, accounts). So, I want a simple «if statement» for it.

I've tried several approaches.

<%= if params[:company_id].present? %> # doesn't work in company views
  # certain link
<% end %>

<%= if current_page?(controller: 'companies') %> # doesn't work in nested controllers' views
  # certain link
<% end %>

Of course, it is possible to use both of them with or, but I think it can be a better way for this.

Thanks!

Peter Tretyakov
  • 3,380
  • 6
  • 38
  • 54

1 Answers1

0

You could use controller_name:

<% if controller_name.match(/^companies/) %>
    # certain link
<% end %>

UPDATE
Alternatively, use controller_path:

<% if controller_path.match(/^companies/i) %> 
    # certain link
<% end %>
Ruby Racer
  • 5,690
  • 1
  • 26
  • 43