邀请控制器
class InvitationsController < Devise::InvitationsController
def new
end
def create
end
end
的routes.rb
devise_for :users, :controllers => { :invitations => 'users/invitations' }
application_controller
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
# Only add some parameters
devise_parameter_sanitizer.for(:accept_invitation).concat [:email]
# Override accepted parameters
devise_parameter_sanitizer.for(:accept_invitation) do |u|
u.permit(:email, :password, :password_confirmation,
:invitation_token)
end
end
users_controller
def new
@user = User.new(:invitation_token => params[:invitation_token])
@user.email = @user.invitation.recipient_email if @user.invitation
end
当我转到'/ users / invitation / new时,我收到错误'未初始化的常量用户'。我错过了什么?感谢
答案 0 :(得分:2)
尝试
devise_for :users, :controllers => { :invitations => 'invitations' }
相反,如果你覆盖方法,你可能需要使用super
来调用父类,如下所示:
```
class InvitationsController < Devise::InvitationsController
def new
super
end
end
```