include bootstrap role attribute in rails form helper
Asked Answered
D

2

9

Twitter Bootstrap has this role attribute for forms:

<form role="form">

How can I include the role attribute in Rails form helpers? I tried this, but it doesn't work:

<%= form_for @user, class: "form-horizontal", role: "form" do |f| %>
Disfigure answered 27/10, 2013 at 18:54 Comment(0)
M
18

You need to specify it as an html option:

<%= form_for @user, html: {class: "form-horizontal", role: "form"} do |f| %>
Monograph answered 27/10, 2013 at 18:59 Comment(4)
Glad to hear! Can you please accept the answer so others know it's been answered?Monograph
This is just to say that what is shown in this answer works, and that with parentheses it does not: <%= form_for(@user), ... -- It yields syntax error, unexpected tLABEL and syntax error, unexpected keyword_do_block, expecting keyword_end.Cherianne
@Cherianne if you wanted to use parens, you'd have to wrap everything, not just the @user object.Monograph
How can I add "role" using "form_tag"?Vertebral
D
1

form_for and form_tag have to be used differently:

form_for:

<%= form_for @user, html: { class: "form-horizontal", role: "form" } do |f| %>

form_tag:

<%= form_tag some_path, class: "form-horizontal", role: "form" do |f| %>
Disfigure answered 19/7, 2014 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.