1

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!

2
  • Are u using twitter- bootstrap gem ? Commented Nov 15, 2012 at 1:40
  • No. Is it recommended to do so? I just downloaded the compiled version of Bootstrap and put them into my assets folder. So far I haven't found any inconvenience. If I use the gem, how is it different for me to use the above form for my post? Commented Nov 15, 2012 at 2:13

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

After I install the gem, does the form_for method automatically use the bootstrap version of input style? I'd appreciate if I could learn the manual way as well..
There is no point in doing it manually for a rails project. Check documentation and the screencasts in the link I posted you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.