# REST hidden\_field verb hack and observe\_form conflict?

**URL:** <https://www.ruby-forum.com/t/rest-hidden-field-verb-hack-and-observe-form-conflict/86497>\
**Category:** Rails\
**Created:** [February 22, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/rest-hidden-field-verb-hack-and-observe-form-conflict/86497 "2007-02-22T19:39:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@christos](https://www.ruby-forum.com/u/christos)\
**Post date:** [February 22, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/rest-hidden-field-verb-hack-and-observe-form-conflict/86497/1 "2007-02-22T19:39:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![christos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@christos](https://www.ruby-forum.com/u/christos)\
**Post date:** [February 22, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/rest-hidden-field-verb-hack-and-observe-form-conflict/86497/2 "2007-02-22T20:18:37Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![christos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@christos](https://www.ruby-forum.com/u/christos)\
**Post date:** [February 22, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/rest-hidden-field-verb-hack-and-observe-form-conflict/86497/3 "2007-02-22T23:27:05Z")

</div>

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
