I’ve got Devise set up with all controllers under “user” like so:
devise_for :users, module: "users"
Now I want to add a get
/account route to show a user’s “registration”, and instinctively thought that this would do it:
devise_for :users, module: "users" do
get "/account", to: "registrations#show", as: "user_registration"
end
But no get
/account route is added:
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
user_registration PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST /users(.:format) users/registrations#create
So I try another way:
devise_for :users, module: "users"
devise_scope :user do
get "/account", to: "registrations#show", as: "user_registration"
end
But now the router complains that I’m intruding in the user_registration
helper space:
`add_route': Invalid route name, already in use: 'user_registration' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
https://guides.rubyonrails.org/routing.html#restricting-the-routes-created
Adding only: [:show]
makes no difference, but it does work if I name the helper to something else, e.g.
devise_for :users, module: "users"
devise_scope :user do
get "/account", to: "registrations#show", as: "something_else"
end
Resulting in the routes:
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
user_registration PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST /users(.:format) users/registrations#create
something_else GET /account(.:format) registrations#show
Unfortunately I’m a picky bastard, and I do not like this option; the helper name should be user_registration
as already present for patch
, put
, delete
and post
and the method should be get
. Is there a nice way to satisfy my OCD?