Rails’ in_place_editor_field – Now Actually Useful!

Sometimes all it takes is a little … objectionism, so to speak. Behold:


def in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {})
tag = ::ActionView::Helpers::InstanceTag.new(object.class.to_s, method, self, nil, object)
tag_options = {:tag => "span", :id => "#{object.class.to_s.downcase}_#{method}_#{object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)
in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object.class.to_s.downcase}_#{method}", :id => object.id })
tag.to_content_tag(tag_options.delete(:tag), tag_options) +
in_place_editor(tag_options[:id], in_place_editor_options)
end

Put that method into in_place_macros_helper.rb of the in_place_editing plugin and you’ll be able to hand it an object instead of a string or a symbol. That way, in_place_editing collections of objects becomes feasible.

Leave a Reply