Tim
Tim

Reputation: 1461

How to change Devise's root controller path in a Rails 3?

I have a Rails 3 app that uses Devise. How do I go about changing devise's root controller to something other than the application's root controller.

In my routes.rb file, I have the applications root set as root :to => 'home#index' so http://app.com/users/sign_in will call up the devise form which is not what I want.

I also have the following in routes.rb (this is the route that I want devise to use):

  scope :module => 'control' do
    constraints :subdomain => 'control' do
      resources :offers
      root :to => 'offers#index'
    end
  end

How can I point devise to use the above path (control.app.com) so that the user sign in would be located at http://control.app.com/users/sign_in?

Thanks!

Tim

Upvotes: 1

Views: 1547

Answers (2)

Tim
Tim

Reputation: 1461

I've found the solution. I added devise_for inside the scope as so:

  scope :module => 'control' do
    constraints :subdomain => 'control' do
      devise_for :users, :module => 'devise'
      resources :offers
      root :to => 'offers#index'
    end
  end

You need to add :module => 'devise' because the module is changed to the namespace's name, so you have to set it back to 'devise'. Now I can access all the devise actions with the control subdomain (ex. control.app.com/users/sign_in, control.app.com/users/sign_up, etc)

Upvotes: 0

neezer
neezer

Reputation: 20560

Maybe you need to use devise_scope when defining your root route for your sign-in page and pass your subdomain in there? Just a guess.

"Configuring routes" in https://github.com/plataformatec/devise/blob/master/README.rdoc may be of some help.

Upvotes: 1

Related Questions