我正在尝试使用 Bootstrap forms在 Rails 中。但是在检查了我的帖子脚手架创建的 _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-rails gem 添加到您的应用程序,而不是手动执行。请在此处获取说明和文档:twitter-bootstrap-rails gem
这样就可以了!
关于html - rails : Using Bootstrap Input Style to Replace the built-in form_for method in Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390267/