views:

424

answers:

3

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" />
+7  A: 
<% 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.

DanSingerman
Nope, syntax error with that... thanks though.
Yar
You're right. Hold on...
DanSingerman
excellent... holding!
Yar
+1, with a method declaration with two = {} parameters, you must indicate when one hash ends and the other starts. {:action => 'whaterver'}, :method => "get" does that.
Samuel
Sweet! Thanks, and thanks Samuel for the explanation.
Yar
A: 

Have you tried

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

ri form_tag gives you examples as well.

Keltia
yeah. that puts the action attribute like this /hello/input002?method=get which is not the idea :)
Yar
Then I have some trouble understanding your question...
Keltia
updated the question to explain better, thanks!
Yar
+2  A: 

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 %>
ucron
Excellent, thanks cyx! I know how to do that now thanks to my own question http://stackoverflow.com/questions/474667
Yar