Maximus S
Maximus S

Reputation: 11095

Rails: Using Bootstrap Input Style to Replace the built-in form_for method in Rails

I am trying to use Bootstrap forms in Rails. But after inspecting the _form partial created by my post scaffold, I'm not quite sure how I can edit the variables with regular input methods.

For example, this is the built-in form code:

<%= 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 %>

I want to use the form code below:

<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>

Question: How do I use Bootstrap version of form code?

I tried something like..

<input class="span10" type="text" name="@post.name" placeholder="Type in name: ">
<button type="submit" class="btn">Submit</button>

But it doesn't seem to work. I thought the Bootstrap submit button is not pointing at the right direction, so I tried the following as well:

<input class="span10" type="text" name="@post.name" placeholder="Type in name: ">
<%= form_for(@post) do |f| %>
 <%= f.submit %>
<% end %>

Could someone please help me with this? I appreciate your help!

Upvotes: 1

Views: 1281

Answers (1)

FedeX
FedeX

Reputation: 446

Instead of doing it manually, you should add twitter-bootstrap-rails gem to your app. Se here for instructions and documentation: twitter-bootstrap-rails gem

That will do the trick!

Upvotes: 1

Related Questions