[英]simple_form validations with Bootstrap in Rails
我的rails應用程序中具有以下simple_form:
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title center">Add New Customer</h3>
</div>
<div class="panel-body">
<%= simple_form_for(@customer, html: {class:'form-horizontal'}, wrapper: :horizontal_form) do |f| %>
<%= f.input :first_name, input_html: {class:'form-control'} %>
<%= f.input :last_name, input_html: {class:'form-control'} %>
<%= f.input :phone_number, as: :tel, input_html: {class:'form-control'} %>
<%= f.input :email_address, as: :email, input_html: {class:'form-control'} %>
<%= f.input :address, input_html: {class:'form-control'} %>
<%= f.input :city, input_html: {class:'form-control'} %>
<%= f.input :postal_code, input_html: {class:'form-control'} %>
<%= f.input :customer_type, collection: ["Retail", "Contractor", "Dealer"], input_html: {class:'form-control'}, prompt: "Select Customer Type" %>
<br />
<%= f.button :submit, "Create Customer", class: "col-md-3 bump-right" %>
<% end %>
</div>
</div>
如您所見,我在表單元素上使用了引導樣式。 提交表單時,我希望發生以下情況:
就目前而言,當我提交表格時,以上三個都沒有發生。 在文檔中尋找simple_form( https://github.com/plataformatec/simple_form ),我無法辨別為達到最終結果而需要做什么。 我嘗試為每個輸入添加f.error字段,但這似乎無濟於事。
有一個2年的歷史問題: simple_form和bootstrap驗證不起作用 -但這對我來說是陌生的,考慮到2.5年的版本,我確定已經有所改變。
如果有人有任何想法,或者可以幫助我揭開文檔的神秘面紗,我將不勝感激。
在模型(特別是客戶模型)中使用驗證,該驗證將在數據保存到數據庫之前進行。 在此處查看文檔。
例:
class Person < ActiveRecord::Base
validates :name, presence: true
end
Person.create(name: "John Doe").valid? # => true
Person.create(name: nil).valid? # => false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.