Harsha M V
Harsha M V

Reputation: 54949

Subdomain not working with Devise Routes

I have the following routes

constraints :subdomain => "brands" do
    scope :module => "brands", :as => "brands" do

      devise_for :members

      # devise_for :users, controllers: {
      #   sessions: 'users/sessions'
      # }


    end
  end

When i go to http://brands.lvh.me:3000/members/sign_up i am getting the following error

ActionController::RoutingError at /members/sign_up

uninitialized constant Brands::RegistrationsController Application Frames All Frames

ActionDispatch::Routing::RouteSet::Dispatcher#controller
actionpack (4.2.5.2) lib/action_dispatch/routing/route_set.rb, line 63

Registration Controller - `app/controllers/brands/members/registrations_controller.rb

class Brands::Members::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]

  # GET /resource/sign_up
  # def new
  #   super
  # end

  # POST /resource
  # def create
  #   super
  # end

  # GET /resource/edit
  # def edit
  #   super
  # end

  # PUT /resource
  # def update
  #   super
  # end

  # DELETE /resource
  # def destroy
  #   super
  # end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_up_params
  #   devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
  # end

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_account_update_params
  #   devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
  # end

  # The path used after sign up.
  # def after_sign_up_path_for(resource)
  #   super(resource)
  # end

  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end
end

Upvotes: 1

Views: 637

Answers (1)

coding addicted
coding addicted

Reputation: 3430

Answer from the comments:

Create a controller to override the devise one. Add there anything specific your need or just inherit from the Devise controller.

Then in your routes you can tell devise to use the controller you just set with:

devise_for :members, controllers: {:sessions => "your_scope/sessions"}

Devise doc (see section about configuring controllers and routes)

The "your_scope" section in the above code is related to the question which used a specific scope.

thought: Devise must be lost with the subdomain and scope thing an is not figuring which and where the controller are supposed to be. So maybe if I'm true, you can even skip the custom controller part and just tell Devise to use it's own and default controllers. In short, tell devise to forget about the scope and use the classic default mechanism.

Upvotes: 1

Related Questions