In place editor with drop downs

Trying to figure out how to do this and came across this page: http://fora.pragprog.com/rails-recipes/write-your-own/post/223

Seems a little confusing as to what is what in the method definitions.

Anyone use it or have another way to get drop downs into the in place editor ?

Confusing regarding above link: 1- In applicationhelper

def in_place_collection_editor_field(object,method,container) # I take it the container is the paramters for the collection Somemodel.find(:all. ... # object, method didn't take as symbols or 'string'.

The final parameter, container, contains the options for the drop-down box. First, resolve a tag and create the submit URL:

tag = ::ActionView::Helpers::InstanceTag.new(object, method, self) # not sure what self is referring to here.
url = url_for( :action => "set_#{object}_#{method}", :id => [
tag.object.id](http://tag.object.id) ) #okay , this makes sense.

Then we move on to the controller code:

On the controller side, you will need to define a method set_object_method to handle the input. Next, start the definition of the function: # am i actually naming it set_object_method or just set_myobject_mymethod ?

function = "new Ajax.InPlaceCollectionEditor(" function << "'#{method}'," function << "'#{url}'," Then, process the options:

collection = container.inject([]) do |options, element| options << "[ '#{html_escape(element.last.to_s)}', '#{html_escape(element.first.to_s)}']" end Finally, add the collection to the final Javascript:

function << "{collection: [#{collection.join(',')}]," function << "});" end

`javascript_tag(function)`

Stuart

RailsRecipes has a recipe for this , so I’m working through that now :slight_smile:

Stuart