Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my form_tag method a post when I am asking for a get?

Tags:

My form_tag looks like:

<%= form_tag(:controller => "users", :action => "confirm", :method => "get") %>

the html output is:

<form accept-charset="UTF-8" action="/users/confirm?method=get" method="post">

Why is it doing this?

like image 487
Blankman Avatar asked Mar 16 '11 03:03

Blankman


People also ask

Why use form_ tag Rails?

This can be used for: creating new database records, building a contact form, integrating a search engine field, and pretty much every other aspect of the application that requires user input. When it comes to forms in Rails, you will discover that you will have the flexibility to utilize: Built-in form helper methods.

What is form in Rails?

Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of the need to handle form control naming and its numerous attributes. Rails does away with this complexity by providing view helpers for generating form markup.


2 Answers

I think it's because when used in this form it assumes all of the options are url options. Try.

<%= form_tag( '/users/confirm', :method => :get ) %>

In this case you have two separate sets of options, url options and tag options.

like image 189
tvanfosson Avatar answered Nov 15 '22 12:11

tvanfosson


The first 2 parameters of form_tag are url_for_options and options. Both are hash. So in your code, the whole hash is taken as url_for_options. So, to separate the parameters, you have to do like this:

<%= form_tag({:controller => "users", :action => "confirm"}, {:method => "get"}) %>

or

<%= form_tag({:controller => "users", :action => "confirm"}, :method => "get") %>

Refer link

like image 36
rubyprince Avatar answered Nov 15 '22 13:11

rubyprince