Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 2 years ago 63
Ruby Question

creating custom routes in rails

I am creating a custom route like this

namespace :admin do
root 'users#index'
resources :users do
get 'admin_login' => 'users#admin_login'


But when I see with
rake routes

admin_user_admin_login GET /admin/users/:user_id/admin_login(.:format) admin/users#admin_login

Why :user_id is added here
I just want it without this :user_id

Answer Source

Because you are creating a custom route within the users resource. Rails is doing exactly what you are telling it to do. You would like to show the "admin_login" route for a specified user (that's what you're currently telling rails to do).

Move the:

get 'admin_login' => 'users#admin_login' 

Line of code outside of the resources block and you'll be able to create your custom route.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download