我在这里和这里找到了类似的StackOverflow问题,但仍然无法使其工作.
我正在使用Rails 3.2.8,SimpleForm 2.0.4和Twitter Bootstrap 2.1.1(通过bootstrap-sass gem 2.1.1.0).
用户应该能够从模态弹出窗口添加联系人.如果存在验证错误,它们应该显示为内联,就像用户使用表单的非模态版本(字段周围的红色边框,字段旁边的错误消息)一样.
我像这样加载模态:
<a data-toggle="modal" data-target="#new-contact-modal">Go modal!</a>
Run Code Online (Sandbox Code Playgroud)
这是Bootstrap模式,它调用contacts/contact_fields非模态版本中使用的相同部分.app/views/contacts/_new_modal.html.erb:
<div id="new-contact-modal" class="modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="new-contact-modal-label"
aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h3 id="new-contact-modal-label"><%= t("contacts.new.header") %></h3>
</div>
<%= simple_form_for(@contact,
:remote => true,
:html => {:class => "form-horizontal",
"data-type" => :json }) do |contact_form| %>
<div id="new-contact-body" class="modal-body">
<%= render 'contacts/contact_fields', :f => contact_form %>
</div>
<div class="modal-footer">
<%= contact_form.submit :class => "btn btn-primary", …Run Code Online (Sandbox Code Playgroud)