Use Rails’ form_for but set custom classes, attributes on <form> element?
Solution 1:
Use the :html
hash:
= form_for @user, :html => {:class => 'x', 'data-bar' => 'baz'} do |f|
Or
= form_for @user, html: {class: 'x', data: { bar: 'baz' } } do |f|
Solution 2:
Rails 4.0.3, Ruby 2.1.0p0 -> this worked for me =>
<%= form_for(@contact, :html => {:class => 'form_height'}) do |f| %><% if @contact.errors.any? %>
Solution 3:
I had the same problem but was puzzled that another form elsewhere in my app was working fine.
I realized that I had accidentally added a form_for inside another form_for which once removed cured the problem.
Secondly, I should add that this syntax works for me in Rails 4.2:
<%= form_for @type, html: {class: "form-horizontal"} do |f| %>
I find it preferable to the punctuation-soup of the other answers here (which were perhaps based on an older Rails version).