嗯,我是rails的新手,我试图在索引动作的模态中创建一个表单,除了打开这个模态以外,我发现所有需要的输入都是红色的,令人困惑,因为我没有点击提交按钮但是检查验证,你可以在屏幕截图中看到,所以我在这里做错了什么?任何帮助表示赞赏
这是index.html.erb中的模态部分
<%= render 'popup' %>
这里是_popup.html.erb
<% content_for :popup do %>
<%- model_class = Supplier -%>
<div class="modal splash fade" id="splash" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1><%= t '.title', :default => model_class.model_name.human.titleize %></h1>
</div>
<div class="modal-body">
<%= render 'form' %>
</div>
</div>
</div>
</div>
<% end %>
这是_form.htm.erb
<%= simple_form_for(@supplier ,remote: true) do |f| %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :code %>
<%= f.input :email , :hint => "should be a valid email "%>
<%= f.input :status %>
<%= f.input :total_credit %>
<%= f.input :user_id,collection: [] || User.all ,label_method: :name , value_method: :id ,include_blank: true %>
<%= f.input :notes %>
</div>
<div class="modal-footer">
<%= f.button :submit %>
</div>
<% end %>
和控制器动作:索引
def index
@suppliers = Supplier.all
@supplier = Supplier.new
end
这是我的模特:
class Supplier < ActiveRecord::Base
has_many :supplier_branches
has_many :supplier_phones
has_many :supplier_contacts
has_many :purchase_invoices
belongs_to :user
validates :name,:code, presence: true
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
end