Rails Client_side_validation错误消息未在turbolinks上生成:加载但在页面加载时生成(页面刷新)。
Rails版本:版本4.2.6 Client_Side_Validation:版本4.2.7
型号:
class Comment < ActiveRecord::Base
validates :content, presence: true
belongs_to :post
belongs_to :user
end
形式:
<%= form_for [@post, @post.comments.build], validate: true do |f| %>
<div class="input-group">
<%= f.text_field :content, class: "form-control", autocomplete: :off %>
<span class="input-group-btn">
<%= f.submit "Send", class: "btn btn-primary pull-right" %>
</span>
</div>
<% end %>
生成的HTML:
<form data-validate="true" novalidate="novalidate" class="new_comment" id="new_comment" action="/posts/21/comments" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="ZmpADuX73JqNvAh5wljYCmk68wXioVLFP1YDHY+71l4YADgQglKiQAODBrc5OrXvioqurjI5/JwqfO2qJXPPvg==" />
<div class="input-group">
<input class="form-control" autocomplete="off" type="text" name="comment[content]" id="comment_content" />
<span class="input-group-btn">
<input type="submit" name="commit" value="Send" class="btn btn-primary pull-right" />
</span>
</div>
</form>
<script>
//<![CDATA[
if(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=["uniqueness"];window.ClientSideValidations.number_format={"separator":".","delimiter":","};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=/^(-|\+)?(?:\d+|\d{1,3}(?:\,\d{3})+)(?:\.\d*)?$/;if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_comment'] = {"type":"ActionView::Helpers::FormBuilder","input_tag":"\u003cdiv class=\"field_with_errors\"\u003e\u003cspan id=\"input_tag\" /\u003e\u003clabel for=\"\" class=\"message\"\u003e\u003c/label\u003e\u003c/div\u003e","label_tag":"\u003cdiv class=\"field_with_errors\"\u003e\u003clabel id=\"label_tag\" /\u003e\u003c/div\u003e","validators":{"comment[content]":{"presence":[{"message":"can't be blank"}]}}};
//]]>
</script>
问题:
生成的输入HTML应如下所示:
<input class="form-control" autocomplete="off" type="text" name="comment[content]" id="comment_content" data-validate="true" />
data-validate="true"
未在turblinks:load
上生成,但在刷新页面时生成正常。
有人知道这方面的解决方案吗?