Reputation: 371
Actually I am using two models for my app that is User and Admin and I followed every steps to be dealt while using devise gem.
And I would like to have multiple sign_up. When User sign_up, must be redirected to User sign_up page and when Admin sign_up, must be redirected to Admin sign_up page in order to make registrations.
When I execute sign_up link under User it gives me routing error which is as below;
Routing Error
uninitialized constant Users::RegistrationsController
And When I execute sign_up link under Admin it gives me routing error which is as below;
Routing Error
uninitialized constant Admins::RegistrationsController
routes.rb
Rails.application.routes.draw do
root "home#index"
devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations'
}
get '/aslani' => 'aslani#index', as: :authenticated_user_root
devise_for :admins, controllers: {
sessions: 'admins/sessions',
registrations: 'admins/registrations'
}
get '/kola' => 'kola#index', as: :authenticated_admin_root
end
aslani/index.html.erb
<% if user_signed_in? %>
I am Aslani.
<%= link_to 'Log out', destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to 'Log In', new_user_session_path %>
<%= link_to 'Sign Up', new_user_registration_path %>
<% end %>
kola/index.html.erb
<% if admin_signed_in? %>
I am Kola.
<%= link_to 'Log out', destroy_admin_session_path, method: :delete %>
<% else %>
<%= link_to 'Log In', new_admin_session_path %></li>
<%= link_to 'Sign Up', new_admin_registration_path %>
<% end %>
app/controllers/users/sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
def new
super
end
def create
self.resource = warden.authenticate!(auth_options)
sign_in(resource_name, resource)
yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource)
end
end
app/controllers/admins/sessions_controller.rb
class Admins::SessionsController < Devise::SessionsController
def new
super
end
def create
self.resource = warden.authenticate!(auth_options)
sign_in(resource_name, resource)
yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource)
end
end
app/controllers/users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
end
app/controllers/admins/registrations_controller.rb
class Admins::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
end
Any suggestions are most welcome.
Thank you in advance.
Upvotes: 0
Views: 152
Reputation: 3427
Per discussion with @Muhammad
He is getting missing template admins/registrations/create error, To solve this, either add super or delete create action because he has overridden nothing
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
end
Upvotes: 1