Routes in ruby on Rails

Asked

Viewed 236 times

2

I have the following routes:

resources :roles do
  resources :role_permissions do
    patch 'toggle_action/:id' => 'role_permissions#toggle_action'
  end
end

I create a link as follows:

role_role_permissions_path(@role, @role_permission, permission_action)

Should mount a route similar to the route below:

# => /roles/1/role_permissions/1/toggle_action/1

But it’s generating a route like:

# => /roles/1/role_permissions/1.1

What could be?

1 answer

0


Just add a alias for the route:

resources :roles do
  resources :role_permissions do
      patch 'toggle_action/:id' => 'role_permissions#toggle_action', as: :toggle_action
  end
end

and to use it:

role_role_permission_toggle_action_path(@role, @role_permission, permission_action)

See the route:

role_role_permission_toggle_action PATCH /roles/:role_id/role_permissions/:role_permission_id/toggle_action/:id(.:format) role_permissions#toggle_action

Browser other questions tagged

You are not signed in. Login or sign up in order to post.