How to use in_place_editor in Rails 2.x
Install the plugin
./script/plugin install git://github.com/rails/in_place_editing.git
We supose that we have a "State" model with a "name" attribute and we want to edit it “in place”. Add in your controller
class StatesController < ApplicationController
in_place_edit_for :state, :name
end
This method adds an action called "set_state_name" which updates the attribute specified, in this case "name" (see the code for more details).
Now, you can use the helper that the plugin adds
<span id="edit_field"><%=h state.name %></span>
<%= in_place_editor 'edit_field', :url => url_for(:action => :set_state_name, :id => state.id) %>
Important Note: This plugin has a problem: it isn't RESTful, you can't do this
<%= in_place_editor 'edit_field', :url => url_for(:action => :update, :id => state.id) %>
The method used to send the form is POST, you can't access a resource via PUT method, therefore you can't access "update" action in the controller.
That's all!