首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用simple_form nested_form和引导-sass Rails 4在水平主窗体中为子记录创建内联窗体

如何使用simple_form nested_form和引导-sass Rails 4在水平主窗体中为子记录创建内联窗体
EN

Stack Overflow用户
提问于 2014-12-02 21:27:19
回答 1查看 835关注 0票数 1

我有水平形式,包括嵌套形式。我希望这个嵌套表单是内联的。我没有成功。子表单输入仍然是水平的,即使我指定了表单内联到simple_fields_for。

_form.html.erb

代码语言:javascript
复制
<%= simple_nested_form_for(@cargo, :html => { :class => "form-vertical" }, :wrapper => false) do |f| %>
<% if @cargo.errors.any? %>
<div id="error_explanation">
    <h2><%= pluralize(@cargo.errors.count, "error") %> prohibited this cargo from being saved:</h2>
    <ul>
        <% @cargo.errors.full_messages.each do |msg| %>
        <li>
            <%= msg %>
        </li>
        <% end %>
    </ul>
</div>
<% end %>

<%= f.association :airport, :label_method => :full_airport_name, :value_method => :id , :order => :iata_code %>
<%= f.input :departure_date, as: :date, start_year: Date.today.year, end_year: Date.today.year + 16, order: [:day, :month, :year] %>
<%= f.association :cargo_description, :label_method => :description, :value_method => :id, :order => :description %>
<%= f.association :cargo_price, :label_method => :price, :value_method => :id %>
<div class="js-dependent-fields" data-select-id="cargo_cargo_price_id" data-option-value="1|2">
  <%= f.input :asked_price, as: :integer %>
</div>
<%= f.association :cargo_state, :label_method => :state, :value_method => :id %>

<%= f.simple_fields_for(:cargo_items, @cargo_item, :html => { :class => "form-inline" }) do |cargo_items_fields| %>
  <%= cargo_items_fields.input :pieces, label: t('cargo_item.pieces'), input_html: { value: '1' } %>
  <%= cargo_items_fields.input :length, label: t('cargo_item.length') %>
  <%= cargo_items_fields.input :width , label: t('cargo_item.width') %>
  <%= cargo_items_fields.input :height, label: t('cargo_item.height') %>
  <%= cargo_items_fields.input :weight, label: t('cargo_item.weight_per_piece') %>
  <%= cargo_items_fields.link_to_remove '', :confirm => t('cargo_item.remove_item_confirmation'), :class => "glyphicon glyphicon-remove" %>
<% end %>

<%= f.link_to_add '', :cargo_items, :class => "glyphicon glyphicon-plus" %>

<div class="actions">
    <%= f.button :submit, :class => "btn btn-primary btn-sm" %>
  <%= link_to t('buttons.back_html'), cargos_path, :class => "btn btn-danger btn-sm" %>
</div>
<% end %>

new.html.erb

代码语言:javascript
复制
<div class="row">
  <%= render partial: 'form', layout: 'form-layout', locals: { title: t('titles.title_cargo_new') } %>
</div>

_form-layout.html.erb

代码语言:javascript
复制
<div class="col-md-8">
  <div class="panel panel-info">
    <div class="panel-heading"><%= title %></div>
    <div class="panel-body">
      <%= yield %>
    </div>
  </div>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-13 21:55:15

通过在表单中硬编码内联类来自己解决问题,所以我不依赖简单的表单div生成器(仅用硬编码的解决方案粘贴嵌套表单):

代码语言:javascript
复制
<div class="form-inline">
<%= f.simple_fields_for(:cargo_items, @cargo_item) do |cargo_items_fields| %>
  <%= cargo_items_fields.input :pieces, label: t('cargo_item.pieces'), input_html: { size: '3', type: "" } %>
  <%= cargo_items_fields.input :length, label: t('cargo_item.length'), input_html: { size: '3', type: "" } %>
  <%= cargo_items_fields.input :width , label: t('cargo_item.width'), input_html: { size: '3', type: "" } %>
  <%= cargo_items_fields.input :height, label: t('cargo_item.height'), input_html: { size: '3', type: "" } %>
  <%= cargo_items_fields.input :weight, label: t('cargo_item.weight_per_piece'), input_html: { size: '3', type: "" } %>
  <%= cargo_items_fields.link_to_remove '', :confirm => t('cargo_item.remove_item_confirmation'), :class => "glyphicon glyphicon-remove" %>
<% end %>
<%= f.link_to_add '', :cargo_items, :class => "glyphicon glyphicon-plus" %>
</div>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27259294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档