ThetaCom Projects

Rails In Place Editing Plugin W Selection

Post migrated from: http://thetacom.info/2008/03/21/rails-in-place-editing-plugin-w-selection

As of Rails 2.0 the in_place_editor methods have been moved into a plugin. You can download this plugin here. For some items I needed to have a dropdown selection instead of a text field. To add this functionality, I added two methods to the plugin.

Here is the full contents of ‘in_place_macros_helper.rb’ Code Pastie

Replace the contents of this file: “your_app/vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb”

Controller Usage:

in_place_edit_for :o bject, :method

example_controller.rb

class MyController < ApplicationController
	in_place_edit_for :user, :theme_color
end

Inserting this in the top of you controller automatically creates a method that update the object and returns the updated value as text to the browser.

View Usage:

in_place_editor_select_field :o bject, method, {tag_options},{:collection => [array], scriptaculous_options}

example_view.html.erb

<label for=user_theme_color_1_in_place_editor>Theme Color:</label>
<%= in_place_editor_select_field :user, ‘theme_color’, {},{:collection => [[ 1 , 'Red' ], [ 2 , 'Green' ], [ 3 , 'Blue' ]]} %>
<br />

UPDATE: Get the new code for the plugin from the pasties link above

*These methods require the prototype and scriptaculous libraries so be sure to include them in your views.