0

I'm creating a Rails app and I'm trying to do not use Devise to handle my registrations & sessions related to my User model but I'm running into an issue.

I'd like to have specific routes like that:

  • http://localhost:3000/users/registrations/new
  • http://localhost:3000/users/sessions/new

I tried several solution but none is working, last try was those lines of code:

get "users/registrations/new", to: "registrations#new", controller: "users/registrations", as: :new_registration
get "users/sessions/new", to: "sessions#new", controller: "users/sessions", as: :new_session

But I got the following error: uninitialized constant RegistrationsController

My registrations_controller and my sessions_controller are in the following path: app/controllers/users/

Is anyone knows how I could handle that? Should I use resources or a namespace? I already tried those solutions but I'm facing the same issue all the time...

Thank you for your help!

raphael-allard
  • 205
  • 2
  • 9

1 Answers1

3

You use to: "namespace/name_of_controller#action", in your case

get "users/registrations/new", to: "users/registrations#new", as: :new_registration
get "users/sessions/new", to: "users/sessions#new", as: :new_session

Another way, and more "Rails-y", is to use namespace

namespace :users do
  resources :registrations, only: [:new] # If you want only the new action
  # ...
end
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54