【问题标题】:Devise Invitable Terms of Service制定可邀请的服务条款
【发布时间】:2017-07-04 10:18:38
【问题描述】:

我正在尝试将服务条款复选框添加到我的设计邀请视图中。 因此发出邀请,工程师点击接受邀请链接并到达以下表格:

<h2><%= t 'devise.invitations.edit.header' %></h2>

<%= simple_form_for resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put } do |f| %>
  <%= devise_error_messages! %>

  <%= f.hidden_field :invitation_token %>

  <%= f.input :first_name %>
  <%= f.input :last_name %>

  <%= f.input :password %>
  <%= f.input :password_confirmation %>

  <%= f.input :terms_of_service, as: :boolean, required: true, label: ("I agree to the #{link_to 'Terms of Service', page_path('terms'), target: :_blank}").html_safe %>

  <%= f.button :submit, t("devise.invitations.edit.submit_button") %>
<% end %>

我的模型是:

class Engineer < ApplicationRecord
  devise :invitable, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessor :terms_of_service
.
.
.
  validates_acceptance_of :terms_of_service, if: :invitation_accepted_at?, acceptance: true, allow_nil: false

我有一个自定义设计控制器:

class CustomDeviseController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?
.
.
.
  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name])
    devise_parameter_sanitizer.permit(:accept_invitation, keys: [:first_name, :last_name, :terms_of_service])
  end

我收到表单错误“必须接受服务条款”,它告诉我验证正在运行。问题似乎是服务条款失败,因为它为零,因此验证失败。我不明白为什么当我勾选复选框时它没有通过并且满足验证?

--- 更新 ---

生成的参数哈希为:

{"utf8"=>"✓", "authenticity_token"=>"aoGCMoYRcmJ2EmpM8L+UmQQcB99FScgA6nFM0kY+53dxDodCZDislej48+lBL4Qcb5ZgAcGHyd1A+3qkIol6KA==", "engineer"=>{"invitation_token"=>"e9oVkxuYMtX9Fzxao7xR", "first_name"=>"sad", "last_name"=>"test", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "terms_of_service"=>"0"}, "commit"=>"Create Account"}
Unpermitted parameter: :terms_of_service

【问题讨论】:

  • 您可以发布表单提交时生成的参数哈希吗?
  • 好吧,我看到触发的动作是更新。尝试将:terms_of_service 放入account_update 参数
  • 还是没有运气。如果我删除了 validates_acceptance_of 上的 allow_nil: false ,即使未选中复选框,它也会通过

标签: ruby-on-rails devise devise-invitable


【解决方案1】:

原来是因为我有一个客户设计控制器,但同时也在 Engineers 下命名空间邀请的东西。我允许错误文件中的参数。

我不得不在 Engineers::InvitationsController 中允许它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多