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

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 Z. [email protected]

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