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| %>
crispychicken
  • 2,592
  • 2
  • 33
  • 50

2 Answers2

18

You need to specify it as an html option:

<%= form_for @user, html: {class: "form-horizontal", role: "form"} do |f| %>
Peter Brown
  • 50,956
  • 18
  • 113
  • 146
  • 1
    Glad to hear! Can you please accept the answer so others know it's been answered? – Peter Brown Oct 27 '13 at 19:09
  • 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`. – user664833 Oct 28 '13 at 20:36
  • 2
    @user664833 if you wanted to use parens, you'd have to wrap everything, not just the `@user` object. – Peter Brown Oct 28 '13 at 21:49
  • How can I add "role" using "form_tag"? – Ryan Jun 19 '14 at 21:40
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| %>
crispychicken
  • 2,592
  • 2
  • 33
  • 50