Entries Tagged 'Ruby on Rails' ↓

In place editing for nested resources in Rails 3

The most common in-place-editor in Rails is In Place Editing. However it doesn’t not work very well with nested resources or non-default routes. I used Rest In Place by Jan Varwig in Rails 3 and I am very happy with it. Here is how:

First, install the plugin. In Rails 3 it is:
rails install plugin git://github.com/janv/rest_in_place.git
Then include the jquery.rest_in_place.js to the scripts loaded on the page you’d like to have the in place editing on.

Once that’s done, make sure the jQuery loader, starts the scripts:

jQuery(".rest_in_place").rest_in_place(); After this, you can add rest_in_place as the class name of the wrapper element around your editable item. Something like this:
<span data-url="/users/1" data-object="user" data-attribute="name">
<%= @user.name %>
</span>

Jan has a pretty good documentation of this on his website. There are some gotchas/points however:

  • Make sure your Show action responds to JSON. This way you won’t get stuck on “Saving…”
  • Currently there is no way to show the validation errors although the save would not proceed if there are any.
  • You can add a CSS for rest_in_place:hover to make sure users know the item is editable. It could also include a cursor:pointer as well.