Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Multiple parameters before do?

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" />
like image 909
Dan Rosenstark Avatar asked Jan 23 '23 21:01

Dan Rosenstark


2 Answers

<% 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.

like image 126
DanSingerman Avatar answered Jan 26 '23 10:01

DanSingerman


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 %>
like image 44
ucron Avatar answered Jan 26 '23 09:01

ucron