Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 9 months ago 17
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


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.