Form_tag is driving me crazy!

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.

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’

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

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 [email protected] wrote:

On Jan 10, 4:18 pm, bigbanger [email protected] 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.

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

On Jan 10, 5:17 pm, “Ryan B.” [email protected] 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.

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

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

On Jan 12, 5:14 am, Phillip K. [email protected] 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.