如何在其他字段旁边显示一个字段使用simple_form和bootstrap

时间:2012-11-22 10:02:23

标签: ruby-on-rails ruby-on-rails-3 twitter-bootstrap simple-form

我的表单目前有两个字段,下拉列表和输入字段。这是我的表格代码:

<div class="offset3 span6">
... # other code not relevant
<div id="topic_questions">
  <%= f.simple_fields_for :topic_questions do |tq| %>
    <%= tq.link_to_remove "Remove below topic" %> <br><br>
    <%= tq.association :topic, collection: @topics, prompt: "Choose a topic", label: false %>
    <%= tq.input :number_question, label: 'Number of questions' %>
  <% end %>
  <p><%= f.link_to_add "Add a topic", :topic_questions %></p>
</div> #topic_questions
</div>

这就是表单的样子:

image http://s7.postimage.org/mprqpg2e3/step2_form.png

但我希望字段输入标签Number of questions将在dropdownlist Choose a topic旁边。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案,这是我的新代码:

<div id="topic_questions">
  <%= f.simple_fields_for :topic_questions do |tq| %>
    <div class="row">
    <div class="span6"><%= tq.link_to_remove "Remove below topic" %></div><br><br>
    <div class="span3"> <%= tq.association :topic, collection: @topics, prompt: "Choose a topic", label: false %></div>
    <%= tq.input :number_question, placeholder: 'Number of questions', label: false, style: 'display: inline' %>
  <% end %>
   </div> # .row
<p><%= f.link_to_add "Add a topic", :topic_questions %></p>
</div>

表单现在看起来像这样:

image http://s12.postimage.org/ko6idrpb1/step_form.png