0
我想驗證我的表單與寶石ClientSideValidations,並與存在真正的工作,但我想驗證與唯一性,但不工作,直到表格被求和,只顯示消息一次。我加了// =需要aplicatios.js rails.validations並安裝了寶石 這是我的表格:驗證與ClientSideValidations寶石
<%= form_for(@category, validate: true) do |f| %>
<% if @category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% @category.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :color %><br>
<%= f.color_field :color %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
和我的模型:
class Category < ActiveRecord::Base
has_many :has_categories
has_many :articles, through: :has_categories
validates :name, presence: true, uniqueness: true
end
謝謝你的回答。我一直在觀看這個教程https://www.youtube.com/watch?v=n_yasDxb8sk,一切正常,但唯一性驗證不適用於我。我不知道我是否會錯過 – LuisC
@LuisC我需要查看錶單的完整代碼。 –
ok我的表單的完整代碼在描述中 – LuisC