Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 7 months ago 11
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'
end

end


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

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.