实际上我正在为我的应用程序使用两个模型,即用户和管理员,我在使用设计宝石时按照每个步骤进行处理。
我想有多个sign_up。当用户sign_up时,必须重定向到User sign_up页面,当Admin sign_up时,必须重定向到Admin sign_up页面才能进行注册。
当我在User下执行sign_up链接时,它给出了路由错误,如下所示;
Routing Error
uninitialized constant Users::RegistrationsController
当我在Admin下执行sign_up链接时,它给出了路由错误,如下所示;
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
阿斯拉尼/ 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 %>
草/ 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 %>
应用程序/控制器/用户/ 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
应用程序/控制器/管理员/ 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
应用程序/控制器/用户/ registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
end
应用程序/控制器/管理员/ registrations_controller.rb
class Admins::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
end
欢迎任何建议。
提前谢谢。
答案 0 :(得分:1)
与@Muhammad进行讨论
他正在丢失模板管理员/注册/创建错误, 要解决这个问题,可以添加超级或删除创建操作,因为他没有覆盖任何内容
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
end