diff options
Diffstat (limited to 'actionpack/lib/action_controller/macros/in_place_editing.rb')
-rw-r--r-- | actionpack/lib/action_controller/macros/in_place_editing.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/macros/in_place_editing.rb b/actionpack/lib/action_controller/macros/in_place_editing.rb new file mode 100644 index 0000000000..d096e57e9e --- /dev/null +++ b/actionpack/lib/action_controller/macros/in_place_editing.rb @@ -0,0 +1,32 @@ +module ActionController + module Macros + module InPlaceEditing #:nodoc: + def self.append_features(base) #:nodoc: + super + base.extend(ClassMethods) + end + + # Example: + # + # # Controller + # class BlogController < ApplicationController + # in_place_edit_for :post, :title + # end + # + # # View + # <%= in_place_editor_field :post, title %> + # + # For help on defining an in place editor in the browser, + # see ActionView::Helpers::JavaScriptHelper. + module ClassMethods + def in_place_edit_for(object, attribute, options = {}) + define_method("set_#{object}_#{attribute}") do + @item = object.to_s.camelize.constantize.find(params[:id]) + @item.update_attribute(attribute, params[:value]) + render :text => @item.send(attribute) + end + end + end + end + end +end |