0
「受諾条件」チェックボックスがオフの場合、申し込みフォームに妥当性チェックエラーが表示されるようにアーカイブします。何らかの理由で、すべてのフィールドの検証メッセージが正しく表示されますが、そのチェックボックスには表示されません。フォーム受け入れ条件の有効性が確認されていません
ユーザー/ new.html.erb:
<%= form_for(@user, url: signup_path) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.text_field :name, class: "login", placeholder: :name
...more fields...
<%= f.check_box :agreement, class: "field login-checkbox" %>
<label class="choice" for="Field"><%= t("agree_terms") %></label>
<%= f.submit t("register"), class: "button btn btn-primary btn-large" %>
<% end %>
モデル/ user.rb:
class User < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 50 }
validates :password, presence: true, length: { minimum: 6 }, allow_nil: true
# this is the validation
validates :agreement, acceptance: { accept: true }
...
end
allow_nil:falseが追加されました! – Kai
このフィールドは、チェックされていても「チェックされていない」と常に検証されます... – Kai