[英]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.