Forum: Ruby on Rails form_remote_for can do :put

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Adam m. (Guest)
on 2007-01-23 17:37
Hello all,

Im tryng to create a remote_form_for in a restful app, but cant get the
method to be put. It appears to default to post if the value is not post
or get.

is there a trick to this or does form_for_remote not have non get/post
methods.

i tried to add the hidden field forcably but wasnt sure on the syntax. i
know i need this output.
<input type="hidden" value="put" name="_method"/>



for the following :method values i get these when inspecting the
rendered page:

rhtml>>>>>>>>>>>>>>>>>>>>>>>  Rendered HTML
:method => 'put'>>>>>>>>>>    method="post"
:method => 'sfsdfsdf'>>>>>    method="post"
:method => 'get'>>>>>>>>>>>   method="get"

form_remote_for usage:
<pre>

<% form_remote_for(
:track,
track,
:url => track_path(track_edit),
:html => { :method => 'put'}) do |f| %>

form stuff here

<%= image_submit_tag 'icons/arrow_refresh' %>

<% end %>
</pre>
unknown (Guest)
on 2007-01-23 20:24
(Received via mailing list)
I've just been doing stuff like this:

<% form_remote_for(:track,
                               :url => track_path(:id => track.id),
                               :method => "PUT") do |f| %>

been working fine for me:-)
Tim
Adam m. (Guest)
on 2007-01-24 00:23
unknown wrote:
> I've just been doing stuff like this:
>
> <% form_remote_for(:track,
>                                :url => track_path(:id => track.id),
>                                :method => "PUT") do |f| %>
>
> been working fine for me:-)
> Tim


hey tim thanks for the reply.

Really? Yours works. Hmmmm.

I was under the impression that the :id assignment was implied through
order. In this case there is no nesting so i figured track was assigned
to id.

Im begging to think that the fact that i have the form nested in a row
of a table, im getting errors there. I checked and there is a list of
_method put hidden fields further up..
unknown (Guest)
on 2007-01-24 06:58
(Received via mailing list)
On Jan 23, 2:23 pm, Adam M. <removed_email_address@domain.invalid> wrote:
> Really? Yours works. Hmmmm.
Yep, I'm using that syntax in a good number of places.  It does the
HTTP PUT and everything works fine.

>
> I was under the impression that the :id assignment was implied through
> order. In this case there is no nesting so i figured track was assigned
> to id.

Sorry I'm not completely following you here, however you definitely
need to pass the :id to singular_word_path() when you want to do a an
update (e.g. HTTP PUT).

>
> Im begging to think that the fact that i have the form nested in a row
> of a table, im getting errors there. I checked and there is a list of
> _method put hidden fields further up..

I haven't tried to do anything with hidden fields in this regaurd but I
suspect it's throwing you off track, not really sure.

good luck
Tim
Adam m. (Guest)
on 2007-01-24 11:28
unknown wrote:
> On Jan 23, 2:23 pm, Adam M. <removed_email_address@domain.invalid> wrote:
>> Really? Yours works. Hmmmm.
> Yep, I'm using that syntax in a good number of places.  It does the
> HTTP PUT and everything works fine.
>
>>
>> I was under the impression that the :id assignment was implied through
>> order. In this case there is no nesting so i figured track was assigned
>> to id.
>
> Sorry I'm not completely following you here, however you definitely
> need to pass the :id to singular_word_path() when you want to do a an
> update (e.g. HTTP PUT).
>
>>
>> Im begging to think that the fact that i have the form nested in a row
>> of a table, im getting errors there. I checked and there is a list of
>> _method put hidden fields further up..
>
> I haven't tried to do anything with hidden fields in this regaurd but I
> suspect it's throwing you off track, not really sure.
>
> good luck
> Tim

Thanks again for your help.

The hidden fields were added automatically from the form_remote_for when
i specified put as the method.

I have started down a in_place_edit path at the moment which is proving
equally difficult under rest. I will try the remote_form_for again.



Adam
Ed Hickey (Guest)
on 2007-01-24 18:16
(Received via mailing list)
On 1/23/07, Adam M. <removed_email_address@domain.invalid> wrote:
> > Tim
I can't get that to work for me.  I 've been using the :html hash for
passing the PUT method as a hidden field.  I've found this method in the
Beast forum and it seems to work.  Though, it does seem like you should
be
able to pass the :method param and have it override POST.

Anyone else have experience with this?

Ed
Mathew S. (Guest)
on 2009-02-01 06:24
Ed Hickey wrote:
> On 1/23/07, Adam M. <removed_email_address@domain.invalid> wrote:
>> > Tim
> I can't get that to work for me.  I 've been using the :html hash for
> passing the PUT method as a hidden field.  I've found this method in the
> Beast forum and it seems to work.  Though, it does seem like you should
> be
> able to pass the :method param and have it override POST.
>
> Anyone else have experience with this?
>
> Ed

I was having a similar problem and in the end it was because
prototype.js wasn't loading and it was sending the form request as GET
instead of POST (or pseudo PUT depends on how you want to think about
it)

in my .htaccess I added this rule

   RewriteCond %{REQUEST_URI} ^/javascripts.*
   RewriteRule .* - [L]

Which allowed prototype.js to load and it worked.

Hope this helps someone!
This topic is locked and can not be replied to.