Lea*_*cim 4 ruby-on-rails twitter-bootstrap
在阅读了建议我使用Simple_form gem和bootstrap集成的答案之后,我安装了它并根据simple_form指令创建了我的表单,但是输入框是向右浮动的.
这是布局.使用部分'shared/reg'调用表单
<div class="container">
<div class="row">
<div class="span8"><%= yield %></div>
<div class="span4">
<%= render 'shared/reg' %>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我简单的表格形式
<%= simple_form_for("user", :url => main_app.user_registration_path, :html => { :class => "form-horizontal" } ) do |f| %>
<%= f.input :name %>
<%= f.input :vote, :collection => [ "For", "Against", "Undecided"] %>
<%= f.input :country, :collection => [ "Canada", "Iceland", "Other"] %>
<%= f.input :email %>
<%= f.input :image, :as => :file %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在下面,您可以看到输入框如何相对于提交按钮向右浮动.
更新

小智 10
.form-actions您可以将按钮包装在控件组中,而不是使用将灰色块中的提交按钮包装起来的类(也可能不适用于您的页面设计):
<div class="control-group">
<div class="controls">
<%= f.button :submit %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果您在.form-horizontal表单上使用类,则只需要这样做.
如果您正在寻找为Rails输出引导样式标记的插入式替换表单构建器,您可能需要检查我放在一起处理此类事物的gem:
https://github.com/potenza/bootstrap_form
以下是如何设置水平样式表单,并提交按钮正确排列:
<%= bootstrap_form_for(@user, html: { class: 'form-horizontal' }) do |f| %>
<%= f.text_field :email %>
<%= f.password_field :password %>
<%= f.password_field :password_confirmation, label: 'Confirm Password' %>
<%= f.control_group do %>
<%= f.primary "Save User" %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是示例输出:
<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post">
<div class="control-group">
<label class="control-label" for="user_email">Email</label>
<div class="controls">
<input id="user_email" name="user[email]" size="30" type="text" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="user_password">Password</label>
<div class="controls">
<input id="user_password" name="user[password]" size="30" type="password" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="user_password_confirmation">Confirm Password</label>
<div class="controls">
<input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="btn btn-primary" name="commit" type="submit" value="Save User" />
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
您应该尝试以下方法:
<%= form_for("user", :url => main_app.user_registration_path, :html => { :class => "form-horizontal" } ) do |f| %>
<fieldset>
<legend>User Registration</legend>
<div class="control-group">
<%= f.label :name, class: "control-label" %>
<div class="controls">
<%= f.text_field :name %></p>
</div>
</div>
<div class="form-actions">
<%= f.submit %>
</div>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
请注意,引导程序对某些类/ html元素使用了一些特定的选择器,因此如果您忘记添加元素或类,其他所有内容都将被搞砸......在这方面,没有余地.
另外,您应该尝试使用simple_form和bootstrap集成.它会让你的生活更轻松.
更新:
<%= simple_form_for("user", :url => main_app.user_registration_path, :html => { :class => "form-horizontal" } ) do |f| %>
<fieldset>
<legend>User Registration</legend>
<%= f.input :name %>
<%= f.input :vote, :collection => [ "For", "Against", "Undecided"] %>
<%= f.input :country, :collection => [ "Canada", "Iceland", "Other"] %>
<%= f.input :email %>
<%= f.input :image, :as => :file %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<div class="form-actions">
<%= f.submit %>
</div>
</fieldset>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20196 次 |
| 最近记录: |