Christos Zisopoulos
2007-Feb-08 01:39 UTC
REST hidden_field verb hack and observe_form conflict?
Listers, I have in routes.rb... map.resources :posts, :member => { :preview => :post } ...in posts/_edit.rhtml... <% remote_form_for :post, :url => task_path(@post), :id => ''edit_form'' ) do |f| %> # rest of the form goes here <% end %> <%= observe_form "edit_form", :url => preview_post_path(@post) %> What happens is that the routing code receives the hidden "_method=put" field from the serialised form and thinks I am doing a PUT when I am actually trying to do a POST. Needless to say a route to my preview function can''t be found and the app barfs out a routing error. Would you say this a bug in the routing code, the observe_form code or just a nasty usage of the form helper on my part? -christos --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christos Zisopoulos
2007-Feb-22 18:38 UTC
REST hidden_field verb hack and observe_form conflict?
Listers, I have in routes.rb... map.resources :posts, :member => { :preview => :post } ...in posts/_edit.rhtml... <% remote_form_for :post, :url => task_path(@post), :id => ''edit_form'' ) do |f| %> # rest of the form goes here <% end %> <%= observe_form "edit_form", :url => preview_post_path(@post) %> What happens is that the routing code receives the hidden "_method=put" field from the serialised form and thinks I am doing a PUT when I am actually trying to do a POST. Needless to say a route to my preview function can''t be found and the app barfs out a routing error. Would you say this a bug in the routing code, the observe_form code or just a nasty usage of the form helper on my part? -christos --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker
2007-Feb-22 19:17 UTC
Re: REST hidden_field verb hack and observe_form conflict?
Christos, Just thinking from a RESTful perspective; Your route is using :member => { :preview => :post }. Given that POST should be mapped to an SQL INSERT shouldn''t you rather be using :new => { :preview => :post } instead if your intention is to POST a new instance of your resource? Otherwise it would make more sense to use :member => { :preview => :put } in case you are want to UPDATE an existing resource object. On Feb 22, 1:38 pm, Christos Zisopoulos <chris...-zTsVz9fE6/I55T7KX7PIFA@public.gmane.org> wrote:> Listers, > > I have in routes.rb... > > map.resources :posts, :member => { :preview => :post } > > ...in posts/_edit.rhtml... > > <% remote_form_for :post, :url => task_path(@post), :id => > ''edit_form'' ) do |f| %> > # rest of the form goes here > <% end %> > <%= observe_form "edit_form", :url => preview_post_path(@post) %> > > What happens is that the routing code receives the hidden > "_method=put" field from the serialised form and thinks I am doing a > PUT when I am actually trying to do a POST. Needless to say a route > to my preview function can''t be found and the app barfs out a routing > error. > > Would you say this a bug in the routing code, the observe_form code > or just a nasty usage of the form helper on my part? > > -christos--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christos Zisopoulos
2007-Feb-22 22:26 UTC
Re: REST hidden_field verb hack and observe_form conflict?
Robert, I have both a :new => { :preview => :post } for new Post previews and a :member => { :preview => :post } for previewing of existing Posts, when they are edited. But I think you are right, it should be :member => { :preview => :put } for my edit previews. That should solve my conflict, although I am still uncertain if the routing behaviour is right when it receives conflicting commands (a POST with a hidden _put). Cheers! -christos On 22 Feb 2007, at 20:17, Robert Walker wrote:> > Christos, > > Just thinking from a RESTful perspective; Your route is using :member > => { :preview => :post }. Given that POST should be mapped to an SQL > INSERT shouldn''t you rather be using :new => { :preview => :post } > instead if your intention is to POST a new instance of your resource? > Otherwise it would make more sense to use :member => { :preview > => :put } in case you are want to UPDATE an existing resource object. > > On Feb 22, 1:38 pm, Christos Zisopoulos <chris...-zTsVz9fE6/I55T7KX7PIFA@public.gmane.org> > wrote: >> Listers, >> >> I have in routes.rb... >> >> map.resources :posts, :member => { :preview => :post } >> >> ...in posts/_edit.rhtml... >> >> <% remote_form_for :post, :url => task_path(@post), :id => >> ''edit_form'' ) do |f| %> >> # rest of the form goes here >> <% end %> >> <%= observe_form "edit_form", :url => preview_post_path(@post) %> >> >> What happens is that the routing code receives the hidden >> "_method=put" field from the serialised form and thinks I am doing a >> PUT when I am actually trying to do a POST. Needless to say a route >> to my preview function can''t be found and the app barfs out a routing >> error. >> >> Would you say this a bug in the routing code, the observe_form code >> or just a nasty usage of the form helper on my part? >> >> -christos > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---