在Rails视图中自定义Bootstrap表单

时间:2014-07-12 12:17:44

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

我无法弄清楚在我的视图中修改我的表单部分的正确格式,看起来像下面的引导表单,带有这样的附加按钮;

<div class="col-lg-9">
<div class="input-group input-group-lg">
  <input type="text" class="form-control">
  <span class="input-group-btn">
    <button class="btn btn-default" type="button">Go!</button>
  </span>
</div><!-- /input-group -->


我希望将表单发布到:home和附加按钮以替换Scaffold中的默认f.submit按钮。这是我想修改的Scaffold表格部分。

    <%= form_for @anesu, :html => { :class => 'form-horizontal' } do |f| %>
  <div class="control-group">
    <%= f.label :home, :class => 'control-label' %>
    <div class="controls">
      <%= f.text_field :home, :class => 'text_field' %>
    </div>
  </div>

  <div class="form-actions">
    <%= f.submit nil, :class => 'btn btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                anesus_path, :class => 'btn' %>
  </div>
<% end %>

请指导我如何格式化我的代码和使用正确的方法

1 个答案:

答案 0 :(得分:2)

<%= form_for @anesu do |f| %>    
  <div class="col-lg-9">
    <div class="input-group input-group-lg">
      <%= f.text_field :home, :class => 'form-control' %>
      <span class="input-group-btn">
        <%= f.submit "Go!", :class => 'btn btn-primary' %>
      </span>
    </div>
  </div>
<% end %>