Rails: a few parameters before this?

I have this syntax that works (since it is from the API, pretty much)

<% form_tag :action => "whatever" do -%> <div><%= submit_tag 'Save' %></div> <% end -%> 

and this that works

 <%= form_tag({:action => "whatever"}, {:method => "get"})%> 

Now I tried to combine them, guessing the syntax. "Get" is not added as a form method, as I hoped. How to read it?

  <% form_tag :action => "whatever",:method => "get" do -%> <div><%= submit_tag 'Save' %></div> <% end -%> 

The form tag should read:

 <form action="hello/whatever" method="get"/> 

not

 <form action="hello/whatever?method=get" /> 
+4
source share
3 answers
 <% form_tag({:action => 'whatever'}, :method => "get") do -%> <div><%= submit_tag 'Save' %></div> <% end -%> 

Looking at the docs API , the problem is that :method should go in the options hash, and :action in the url_for_options hash, and you need additional curly braces so that the interpreter knows that they are different hashes.

+7
source

I would say that the best way to do this is to not use anonymous route names and use named routes. It’s much better and cleaner, for example,

 <% form_tag discussions_path, :method => 'get' do %> <div><%= submit_tag 'Save' %></div> <% end %> 
+2
source

You tried

 <% form_tag(:action => "whatever", :method => "get") do -%> <div><%= submit_tag 'Save' %></div> <% end -%> 

ri form_tag gives you examples.

0
source

All Articles