Forum: Ruby on Rails REST hidden_field verb hack and observe_form conflict?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
67f61f0c385168c4b2e5b8fd733c397f?d=identicon&s=25 Christos Zisopoulos (Guest)
on 2007-02-22 19:39
(Received via mailing list)

I have in routes.rb...

  map.resources :posts, :member => { :preview => :post } 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

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?

21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-02-22 20:18
(Received via mailing list)

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 <>
67f61f0c385168c4b2e5b8fd733c397f?d=identicon&s=25 Christos Zisopoulos (Guest)
on 2007-02-22 23:27
(Received via mailing list)

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).

This topic is locked and can not be replied to.