如何在轨道4中将部分形式渲染为水平形式

时间:2015-07-16 23:17:48

标签: html css ruby-on-rails form-for

我的主页上有一个部分(由ajax触发),它由一个表单组成。我希望表单水平显示而不是垂直显示。我已尝试过包装<form class="form-inline">我尝试过<%=f.number_field :pointsSpend, :class => "checkbox inline"%>然后将css更改为display: inline,但似乎没有任何效果

呈现部分的主要形式:

 <div class="row">
        <div class="col-md-12">
            <%= link_to image_tag("biceps.jpg"),'#', id: 'ChallengeButton', class: "btn btn-lg btn-primary" %>
            <div id="challengeCentre"></div>
        </div>
    </div>

表格

<%= form_for(@challenge) do |f| %>

  <% if @challenge.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@challenge.errors.count, "error") %> prohibited this challenge from being saved:</h2>

      <ul>
      <% @challenge.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :pointsSpend %><br>
    <%= f.number_field :pointsSpend %>
  </div>
  <div class="field">
    <%= f.label :rules %><br>
    <%= f.text_area :rules %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

</form>

1 个答案:

答案 0 :(得分:1)

您应该能够将类传递给form_for方法,如下所示:

<%= form_for(@challenge, html: { class: 'form-inline' }) do |f| %>

  <% if @challenge.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@challenge.errors.count, "error") %> prohibited this challenge from being saved:</h2>

      <ul>
      <% @challenge.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :pointsSpend %><br>
    <%= f.number_field :pointsSpend %>
  </div>
  <div class="field">
    <%= f.label :rules %><br>
    <%= f.text_area :rules %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

</form>