comfy / active_link_to

Rails view helper to manage "active" state of a link
MIT License
844 stars 84 forks source link

Nested Controllers #51

Closed sunnyrjuneja closed 7 years ago

sunnyrjuneja commented 7 years ago

Hi Comfy,

Based on a few tests, I don't believe the active option handles nested controllers correctly.

# url: http://localhost:3000/invitations/new
# routes.rb
scope module: 'organizations' do
  resources :invitations, only:  [:new, :create] do
    ...
  end
end

# View attempts:
<%= active_link_to 'Accounts', accounts_path, active: [['organizations::invitations'], ['new']] %>
<%= active_link_to 'Accounts', accounts_path, active: [['invitations'], ['new']] %>
sunnyrjuneja commented 7 years ago

I ended up making a helper that worked perfectly.

def accounts_invitations?
  controller_name == 'accounts' && action_name == 'index' or
    controller_name == 'invitations' && action_name == 'new'
end
GBH commented 7 years ago

try:

<%= active_link_to 'Accounts', accounts_path, active: [[accounts: :index], [invitations: :new] %>

Personally it I think it's still pretty awkward, so a helper you have there is probably better.

sunnyrjuneja commented 7 years ago

Thanks for your assistance @GBH.