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