# In\_place\_editor with resful routes

**URL:** <https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166>\
**Category:** Rails\
**Created:** [January 23, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166 "2007-01-23T23:53:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 23, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/1 "2007-01-23T23:53:27Z")

</div>

Im trying to implement an inline editor for table data. The problem ok  
is pressed and no route can be found. Im attempted to send the result to  
the update controller method so put tracks/3 eg named route  
track\_path(id) with method =\> put

an example row from a track partial below:

"\>\<%= track.title %\>

\<%= in\_place\_editor “#{dom\_id(track)}\_title”,  
{:url =\> url\_for(track\_path(track)), :method=\>“PUT”} %\>

On selecting OK i get: no route match found with gt: tracks/3 gt etc  
:method=\>‘put’

note when i alter the named route to read: tracks\_path(track) it gets to  
the create method. Meaning that i just need to set the method to put.  
Man this put/update issue has plauged me on many fronts today.

i was considering using the scriptaculos js script directally but wasnt  
sure how to proceed.

any help would be greatly appreciated.

Adam

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 24, 2007, 1:58am UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/2 "2007-01-24T01:58:11Z")

</div>

Have you tried starting with in\_place\_edit\_for in your controller,  
rather than configuring the url and action manually?

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 24, 2007, 10:23am UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/3 "2007-01-24T10:23:25Z")

</div>

Carl J. wrote:

> Have you tried starting with in\_place\_edit\_for in your controller,  
> rather than configuring the url and action manually?

Yes i tried that with the in\_place\_edit\_field. the problem is that im  
using restful only routes so there is no way for the action that is  
added by in-place\_edit\_for to be accessed.

Also, im using a partial which isnt playing well with the  
in\_place\_edit\_field. There is a problem with variable scope, the id cant  
be found and ive had to add an ugly work around, which from memory is  
like the code below:

\<% @track = track %\>

i like the concept of restful apps but when things like this come up it  
seems like a pain.

should i perhaps add a non restful named route?

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 24, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/4 "2007-01-24T19:54:13Z")

</div>

I’m using in\_place\_editor\_for with RESTful routes without a problem.  
Need more details on what issues you are seeing. If I recall, the action  
generated by in\_place\_editor\_for was not really RESTful, but I didn’t  
really care that much since AJAX URLs aren’t seen anyway.

> Also, im using a partial which isnt playing well with the  
> in\_place\_edit\_field. There is a problem with variable scope, the id cant  
> be found and ive had to add an ugly work around, which from memory is  
> like the code below:
> 
> \<% @track = track %\>

Yup this is a known issue, I had to do the same thing.

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 24, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/5 "2007-01-24T22:09:58Z")

</div>

Carl J. wrote:

> I’m using in\_place\_editor\_for with RESTful routes without a problem.  
> Need more details on what issues you are seeing. If I recall, the action  
> generated by in\_place\_editor\_for was not really RESTful, but I didn’t  
> really care that much since AJAX URLs aren’t seen anyway.
> 
> > Also, im using a partial which isnt playing well with the  
> > in\_place\_edit\_field. There is a problem with variable scope, the id cant  
> > be found and ive had to add an ugly work around, which from memory is  
> > like the code below:
> > 
> > \<% @track = track %\>
> 
> Yup this is a known issue, I had to do the same thing.

Hey carl, thanks for your reply.

I managed to get around the above ugly fix by using the in\_place\_edit  
control. Note, you do need the simplyhelpful plugin for the dom\_id  
helper.

Ok, so details of the problem im having, with in\_place\_editor and  
restful routes.  
When i click on the ok button from the in\_place\_editor i get an alert  
type error suggesting that there is no route available. What routes do  
you have configured to accept the ajax request? Do you have the  
following included in your routes:  
map.connect ‘:controller/:action/:id’ ?

If i alter the named route from track\_path(track) to tracks\_path it gets  
to the create method. So it appears to be a problem with the lack of a  
put.

It would be nice to no be restful for these ajax items some times  
though. For example i mentioned auto\_complete today and now is a  
requirement, nice one!! These also fail under similar circumstances (no  
route found etc)

=========================VIEW CODE START

\<span id=“\<%= “#{dom\_id(track)}\_artist” %\>”\>\<%= track.artist %\>  
\<%= in\_place\_editor “#{dom\_id(track)}\_artist”, {:url =\>  
url\_for(track\_path(track)), :method=\>:put} %\>

=========================VIEW CODE END

=========================ERROR START

The page at [http://0.0.0.0:3000](http://0.0.0.0:3000) says:  
.  
.  
.  
error communicating with the server  
Action controller :exception caught  
Routing Error  
no route found to match &quote;/tracks/17& quote; with  
{:method=&=gt;:post}

=========================ERROR END

=========================ROUTES START

ActionController::Routing::Routes.draw do |map|  
map.resources :tracks, :prices, :attachments  
map.connect ‘’, :controller =\> “releases”  
end

=========================ROUTES END

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 24, 2007, 11:11pm UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/6 "2007-01-24T23:11:58Z")

</div>

> \<span id="\<%= “#{dom\_id(track)}\_artist” %\>"\>\<%= track.artist %\>  
> \<%= in\_place\_editor “#{dom\_id(track)}\_artist”, {:url =\>  
> url\_for(track\_path(track)), :method=\>:put} %\>

Don’t specify :url at all. Take it out, and put in\_place\_edit\_for at the  
top of the view’s controller. That’s the basic in\_place\_editing  
functionality… I would start by seeing if that works (it’s all I did  
for mine).

Carl

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 25, 2007, 3:23am UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/7 "2007-01-25T03:23:01Z")

</div>

> Just to check, does yours read in\_place\_editor\_field or in\_place\_editor

I use in\_place\_editor\_field with :external\_control.

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [January 24, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/8 "2007-01-24T23:15:03Z")

</div>

Carl J. wrote:

> > \<span id="\<%= “#{dom\_id(track)}\_artist” %\>"\>\<%= track.artist %\>  
> > \<%= in\_place\_editor “#{dom\_id(track)}\_artist”, {:url =\>  
> > url\_for(track\_path(track)), :method=\>:put} %\>
> 
> Don’t specify :url at all. Take it out, and put in\_place\_edit\_for at the  
> top of the view’s controller. That’s the basic in\_place\_editing  
> functionality… I would start by seeing if that works (it’s all I did  
> for mine).
> 
> Carl

Just to check, does yours read in\_place\_editor\_field or in\_place\_editor  
?

---

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [March 15, 2008, 9:48am UTC](https://www.ruby-forum.com/t/in-place-editor-with-resful-routes/83166/9 "2008-03-15T09:48:21Z")

</div>

here is the patch:  
[http://dev.rubyonrails.org/attachment/ticket/10055/in\_place\_editing\_should\_work\_with\_csrf\_and\_rjs.patch](http://dev.rubyonrails.org/attachment/ticket/10055/in_place_editing_should_work_with_csrf_and_rjs.patch)

also, you can take a look at:  
[http://blog.enjoyrails.com/2008/03/15/in\_place\_editor-for-rails202/](http://blog.enjoyrails.com/2008/03/15/in_place_editor-for-rails202/)  
and  
[http://cookbook.enjoyrails.com/cookbooks/20](http://cookbook.enjoyrails.com/cookbooks/20)

Carl J. wrote:

> > Just to check, does yours read in\_place\_editor\_field or in\_place\_editor
> 
> I use in\_place\_editor\_field with :external\_control.
