# Form\_tag is driving me crazy!

**URL:** <https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663>\
**Category:** Rails\
**Created:** [January 11, 2008, 1:19am UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663 "2008-01-11T01:19:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 11, 2008, 1:19am UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/1 "2008-01-11T01:19:00Z")

</div>

I’ve been using Rails for a while and am fairly comfortable with it,  
but I keep stumbling when using form\_for and form\_tag. I’m using  
RESTful routes and simply want to create a form using form\_tag that  
specifies :method =\> :put and an onsubmit handler. I’ve tried things  
like

\<% form\_tag ({:url =\> password\_path(id)}, {:html =\> {:method  
=\> :put, :onsubmit =\> “return true;”}}) do %\>  
…  
\<% end %\>

and

\<% form\_tag (:url =\> password\_path(id), :method =\> :put, :onsubmit =\>  
“return true;”}) do %\>  
…  
\<% end %\>

and

\<% form\_tag :url =\> password\_path(id), :method =\> :put, :onsubmit =\>  
“return true;”) do %\>  
…  
\<% end %\>

and can’t get the method in the form to be set to ‘put’. Also, some  
of these produce some pretty odd form actions…

I’m obviously missing something with the form\_tag syntax here, but  
it’s not clear what it is. FYI, I’m using Rails 2.0.2.

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 11, 2008, 1:24am UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/2 "2008-01-11T01:24:16Z")

</div>

This one gets me almost there:

\<% form\_tag (password\_path(id), {:method =\> :put, :onsubmit =\> “return  
true;”}) do %\>  
…  
\<% end %\>

but the form method is still ‘post’

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 11, 2008, 1:32am UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/3 "2008-01-11T01:32:19Z")

</div>

Does this work? (I prefer form\_for over form\_tag…)

form\_for(:user, :url =\> password\_path(@user), :html =\> {:method =\> :put,  
:onsubmit =\> ‘return false;’}) do |f|  
…  
end

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 11, 2008, 2:18am UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/4 "2008-01-11T02:18:42Z")

</div>

When using PUT in forms the method will always be post in the forms. The  
form is not what sends that method, it’s rather the javascript that’s  
triggered when you submit that form. Don’t put spaces before your  
parenthesis either, do form\_tag() instead of form\_tag ()

On Jan 11, 2008 10:53 AM, bigbanger [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jan 10, 4:18 pm, bigbanger [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > “return true;”) do %\>  
> > …  
> > \<% end %\>
> > 
> > and can’t get the method in the form to be set to ‘put’. Also, some  
> > of these produce some pretty odd form actions…
> > 
> > I’m obviously missing something with the form\_tag syntax here, but  
> > it’s not clear what it is. FYI, I’m using Rails 2.0.2.

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 12, 2008, 7:32am UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/5 "2008-01-12T07:32:57Z")

</div>

On Jan 10, 5:17 pm, “Ryan B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When using PUT in forms the method will always be post in the forms. The  
> form is not what sends that method, it’s rather the javascript that’s  
> triggered when you submit that form. Don’t put spaces before your  
> parenthesis either, do form\_tag() instead of form\_tag ()

Ryan, thanks. I discovered that shortly after I posted and I deleted  
my post, but I guess it hung around long enough for it to be viewed by  
a few people. Thanks again for responding.

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 12, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/6 "2008-01-12T14:15:24Z")

</div>

On Jan 12, 2008, at 12:32 AM, bigbanger wrote:

> Ryan, thanks. I discovered that shortly after I posted and I deleted  
> my post, but I guess it hung around long enough for it to be viewed by  
> a few people. Thanks again for responding.

Actually, if you submitted it via ruby-forum or google-groups, your  
post gets submitted to a mailing list, so even if you deleted it  
right after posting, everyone subscribed to list would have received it.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [April 17, 2008, 10:05pm UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/7 "2008-04-17T22:05:44Z")

</div>

Jeremy Weiskotten wrote:

> Does this work? (I prefer form\_for over form\_tag…)
> 
> form\_for(:user, :url =\> password\_path(@user), :html =\> {:method =\> :put,  
> :onsubmit =\> ‘return false;’}) do |f|  
> …  
> end

Jeremy,

Curious about your preference, because I was trying to use form\_for  
(it’s designed for forms related to models) but kept running into  
trouble using a collection\_select to get a pop-up supplying values from  
a has\_one table. Suppose in your example of “user” you wanted to select  
role from an ancillary table of roles {“novice”, “admin”, “super admin”}

Would you use f.collection\_select? I’ve been trying to get that to  
work, and always have to drop back to form\_tag and specify my model and  
collection implicitly.

Cheers,

Jim

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [January 12, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/form-tag-is-driving-me-crazy/125663/8 "2008-01-12T17:14:29Z")

</div>

On Jan 12, 5:14 am, Phillip K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Actually, if you submitted it via ruby-forum or google-groups, your  
> post gets submitted to a mailing list, so even if you deleted it  
> right after posting, everyone subscribed to list would have received it.

Ahh, that explains it. Thanks Phillip.
