Ruby on rails Desive gem中针对两种类型用户的单一登录页面
使用Desive gem:- 在我的应用程序中,我有两种类型的用户 1) 公司 2) 雇员 我有两个单独的模型为两个用户,我想给单一的登录页面为两个用户 我已经为使用Desive的两个用户生成了不同的视图,但我还需要单次登录 所以这是怎么可能的,请帮我解决 我试试这个:- 控制器/公司/会话\u controller.rbRuby on rails Desive gem中针对两种类型用户的单一登录页面,ruby-on-rails,ruby,ruby-on-rails-3,devise,Ruby On Rails,Ruby,Ruby On Rails 3,Devise,使用Desive gem:- 在我的应用程序中,我有两种类型的用户 1) 公司 2) 雇员 我有两个单独的模型为两个用户,我想给单一的登录页面为两个用户 我已经为使用Desive的两个用户生成了不同的视图,但我还需要单次登录 所以这是怎么可能的,请帮我解决 我试试这个:- 控制器/公司/会话\u controller.rb def create @employee = Employee.new @company = Company.new if @company.email_exis
def create
@employee = Employee.new
@company = Company.new
if @company.email_exist?(params[:company][:email])
super
elsif @employee.email_exist?(params[:company][:email])
params[:employee]=params[:company]
redirect_to employee_session_path(params)
end
end
def create
super
end
employee_session_path是员工会话创建方法的路径,但它始终调用员工会话的新方法
控制器/员工/会话\u controller.rb
def create
@employee = Employee.new
@company = Company.new
if @company.email_exist?(params[:company][:email])
super
elsif @employee.email_exist?(params[:company][:email])
params[:employee]=params[:company]
redirect_to employee_session_path(params)
end
end
def create
super
end
电子邮件存在吗?方法检查两个模型中由任何用户提供的电子邮件id
在我的模型中:
company.rb
def email_exist?(email)
if Company.find_by(email: email)
return true
end
end
employee.rb
def email_exist?(email)
if Employee.find_by(email: email)
return true
end
end
提前感谢 CanCan和Rolify似乎是您寻找的解决问题的组合堆栈。以下是指向github页面的链接: 角色化 坎坎和铁路公司
如果您需要任何帮助,请告诉我试试这个,这可能有助于CanCan是身份验证的好工具,您可以随时使用它。在这里你可以看到一个很好的实现