I have this syntax which works (since it's from the API, pretty much)
<% form_tag :action => "whatever" do -%>
<div><%= submit_tag 'Save' %></div>
<% end -%>
and this, which works
<%= form_tag({:action => "whatever"}, {:method => "get"})%>
Now I have tried to combine them, guessing the syntax. The "get" does not get added as the form method as I had hoped. How should this read?
<% form_tag :action => "whatever",:method => "get" do -%>
<div><%= submit_tag 'Save' %></div>
<% end -%>
Form tag should read:
<form action="hello/whatever" method="get"/>
not
<form action="hello/whatever?method=get" />
<% form_tag({:action => 'whatever'}, :method => "get") do -%>
<div><%= submit_tag 'Save' %></div>
<% end -%>
Looking at the API docs, the issue is that :method
needs to go in the options
hash, and the :action
in the url_for_options
hash, and you need the extra curly brackets so the interpreter knows they are different hashes.
I'd say that the best way to do this is not use anonymous route names and use named routes. It's a lot better and cleaner that way e.g.
<% form_tag discussions_path, :method => 'get' do %>
<div><%= submit_tag 'Save' %></div>
<% 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