【发布时间】:2012-11-15 01:29:38
【问题描述】:
我正在尝试在 Rails 中使用 Bootstrap forms。但是在检查了我的 post 脚手架创建的 _form 部分后,我不太确定如何使用常规输入法编辑变量。
例如,这是内置的表单代码:
<%= form_for(@post) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我想使用下面的表单代码:
<form>
<fieldset>
<legend>Start posting</legend>
<label>Name</label>
<input class="span10" type="text" placeholder="Name: ">
<label>Content</label>
<input class="span10" type="text" placeholder="Content: ">
<textarea rows="10"></textarea>
<button type="submit" class="btn">Submit</button>
</fieldset>
</form>
问题:如何使用 Bootstrap 版本的表单代码?
我试过类似..
<input class="span10" type="text" name="@post.name" placeholder="Type in name: ">
<button type="submit" class="btn">Submit</button>
但它似乎不起作用。我认为 Bootstrap 提交按钮没有指向正确的方向,所以我也尝试了以下操作:
<input class="span10" type="text" name="@post.name" placeholder="Type in name: ">
<%= form_for(@post) do |f| %>
<%= f.submit %>
<% end %>
有人可以帮我解决这个问题吗?感谢您的帮助!
【问题讨论】:
-
你在使用 twitter-bootstrap gem 吗?
-
没有。是否建议这样做?我刚刚下载了 Bootstrap 的编译版本并将它们放入我的资产文件夹中。到目前为止,我还没有发现任何不便。如果我使用 gem,那么在我的帖子中使用上述表单有何不同?
标签: html css ruby-on-rails forms