I have the following line of haml:
=form_tag :action => 'create', :controller => 'comments', :class => 'comment_form' do
But the html that gets output is:
<form accept-charset="UTF-8" action="/comments?class=comment_form" method="post"></form>
I want to set the class. How do I do this?
<– Update –>
With this:
=form_tag ({ :action => 'create', :controller => 'comments' }, { :class => 'comment_form' }) do
I get this error:
syntax error, unexpected ',', expecting ')'
...', :controller => 'comments' }, { :class => 'comment_form' }...
<– Second Update –>
The problem above is the space between ‘form_tag’ and ‘(‘ @woahdae’s answer is correct
form_tag takes 2 options hashes, the first being passed to url_for, the second being passed to the form builder.
So, you have to do it like:
otherwise Rails thinks all the key/value pairs are for url_for, which will append any keys it doesn’t understand as query parameters.