我在我的 rails 应用程序中使用 strong_parameters 和 devise_invitable。如果我将其保留为“禁止属性”运行时错误,我会得到。所以我做了以下事情:
- 使用创建了一个新控制器
rails g controller users/invitations
- 添加
:invitations => "users/invitations"
到 devise_for 填充用户/invitations.rb 像这样:
class Users::InvitationsController < Devise::InvitationsController def update self.resource = resource_class.accept_invitation!(allowed_params) if resource.errors.empty? set_flash_message :notice, :updated sign_in(resource_name, resource) respond_with resource, :location => after_accept_path_for(resource) else respond_with_navigational(resource){ render :edit } end end private def allowed_params params.permit(:utf8,:authenticity_token,:invitation_token, :_method, {user: [:invitation_token,:password,:password_confirmation]}, :commit, :action,:controller) end end
但是,当我这样做时,我收到错误“邀请令牌不能为空”。我已经检查了 allowed_params 的值,使用puts
它似乎在那里。然而,我仍然得到错误。