私はvalidates_acceptance_of :terms, :message => "must be accepted"
自分のuser.rb
モデルで使用しており、使用していbootstrap-sass
ます。
私のチェックボックスのコードは、ビューでは次のようになります。
<div class="control-group">
<%= f.label :terms, :class => "control-label" do %>
Accept <%= link_to('Terms of Use *', "#myTOUModal", :"data-toggle" => "modal") %>
<% end %>
<div class="controls">
<%= f.check_box :terms %>
</div>
</div>
何らかの理由で、フォームの送信時に用語チェック ボックスが選択されていない場合、適切なエラー メッセージがフォームの上部に表示されますが、field_with_errors
div クラスがチェック ボックス ラベルをラップすることに問題があります。
レンダリングされたページの HTML は次のようになります。
<div class="control-group">
<label class="control-label" for="user_terms">
Accept <a href="#myTOUModal" data-toggle="modal">Terms of Use *</a>
</label>
<div class="controls">
<input name="user[terms]" type="hidden" value="0" />
<div class="field_with_errors">
<input id="user_terms" name="user[terms]" type="checkbox" value="1" />
</div>
</div>
</div>
その結果、チェック ボックス フィールド ラベルがエラーで強調表示されません。クラスの div タグの配置を強制的にタグのfield_with_errors
直後に表示する方法はあり<div class="control-group">
ますか? ブロックを使用してフィールド ラベルを定義すると、field_with_errors
タグの配置が乱れるのはなぜですか? 誰もこれを経験していますか?
ありがとうございました