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:
= form_tag({:action => 'create',...}, {:class => 'comment_form'}) do
otherwise Rails thinks all the key/value pairs are for url_for, which will append any keys it doesn't understand as query parameters.
This works for me:
form_tag named_route, :method => :put, :class => 'disable_on_submit'
With Rails 3.0.15
On Rails 5, you can do the following:
<%= form_tag(your_named_path, {class: 'form-inline'}) do %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With