Forum: Ruby on Rails in_place_editor with resful routes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
812d47a4d6c863de5059670b1e33014f?d=identicon&s=25 Adam madd02 (madd02)
on 2007-01-23 23:53
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:


<td>
<span id="<%= "#{dom_id(track)}_title" %>"><%= track.title %></span>

<%= in_place_editor "#{dom_id(track)}_title",
{:url => url_for(track_path(track)), :method=>"PUT"} %>
</td>

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
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-24 01:58
Have you tried starting with in_place_edit_for in your controller,
rather than configuring the url and action manually?
812d47a4d6c863de5059670b1e33014f?d=identicon&s=25 Adam madd02 (madd02)
on 2007-01-24 10:23
Carl Johnson 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?
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-24 19:54
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.
812d47a4d6c863de5059670b1e33014f?d=identicon&s=25 Adam madd02 (madd02)
on 2007-01-24 22:09
Carl Johnson 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 %></span>
<%= 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 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
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-24 23:11
> <span id="<%= "#{dom_id(track)}_artist" %>"><%= track.artist %></span>
> <%= 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
812d47a4d6c863de5059670b1e33014f?d=identicon&s=25 Adam madd02 (madd02)
on 2007-01-24 23:15
Carl Johnson wrote:
>
>> <span id="<%= "#{dom_id(track)}_artist" %>"><%= track.artist %></span>
>> <%= 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
?
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-25 03:23
> Just to check, does yours read in_place_editor_field or in_place_editor

I use in_place_editor_field with :external_control.
394a1191772f4f195b0fb613abdf545a?d=identicon&s=25 Devon Devon (devony)
on 2008-03-15 09:48
here is the patch:
http://dev.rubyonrails.org/attachment/ticket/10055...

also, you can take a look at:
http://blog.enjoyrails.com/2008/03/15/in_place_edi...
and
http://cookbook.enjoyrails.com/cookbooks/20

Carl Johnson wrote:
>> Just to check, does yours read in_place_editor_field or in_place_editor
>
> I use in_place_editor_field with :external_control.
This topic is locked and can not be replied to.