Sha256: aa598d9c75dc243a86e42c4b27d27e452a8f29b5c74aa36d0d79cf67273d2a2e

Contents?: true

Size: 790 Bytes

Versions: 23

Compression:

Stored size: 790 Bytes

Contents

module InPlaceEditing
  def self.included(base)
    base.extend(ClassMethods)
  end

  # Example:
  #
  #   # Controller
  #   class BlogController < ApplicationController
  #     in_place_edit_for :post, :title
  #   end
  #
  #   # View
  #   <%= in_place_editor_field :post, 'title' %>
  #
  module ClassMethods
    def in_place_edit_for(object, attribute, options = {})
      define_method("set_#{object}_#{attribute}") do
        unless [:post, :put].include?(request.method) then
          return render(:text => 'Method not allowed', :status => 405)
        end
        @item = object.to_s.camelize.constantize.find(params[:id])
        @item.update_attribute(attribute, params[:value])
        render :text => CGI::escapeHTML(@item.send(attribute).to_s)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
in_place_editing-1.1.0 lib/in_place_editing/controller_methods.rb
branston-0.6.6 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.6.5 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.6.4 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.6.3 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.6.2 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
in_place_editing-1.0.0 lib/in_place_editing.rb
branston-0.6.1 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.6.0 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.5.2 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.5.1 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.5.0 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.6 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.5 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.4 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.3 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.2 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.1 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.4.0 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb
branston-0.3.6 lib/branston/vendor/plugins/in_place_editing/lib/in_place_editing.rb