【发布时间】:2019-05-11 11:32:31
【问题描述】:
我正在使用 Devise 进行学生身份验证,并且我还有其他名为 show_profile 和 edit_profile 的操作,因此学生可以查看和编辑他的个人资料。
问题是我改写的控制器写入了 Devise 控制器,因此登录/注册停止工作。如何使我的控制器成为 Devise 控制器的扩展?
如果我把这两个:
class Students::RegistrationsController < Devise::RegistrationsController
class StudentsController < ApplicationController
并在登录class StudentsController < ApplicationController 时评论此内容,登录后此class Students::RegistrationsController < Devise::RegistrationsController 有效。
class Students::RegistrationsController < Devise::RegistrationsController
#class StudentsController < ApplicationController
private
def secure_params
params.require(:student).permit(:name, :father_name, :grand_father_name)
end
public
before_action :authenticate_student!
def show_profile
@student = current_student
end
def edit_profile
@student = current_student
end
def update_profile
@student = current_student
if @student.update_attributes(secure_params)
redirect_to(:action => 'show_profile',:id => @student.id )
flash[:notice] = "student edited successfully"
else
render('edit_profile')
end
end
end
【问题讨论】:
标签: ruby-on-rails devise