Sha256: 162cfe53f7b99c46e48e3dffd59670283e0eea281129a121f555ec89b4670c80
Contents?: true
Size: 808 Bytes
Versions: 96
Compression:
Stored size: 808 Bytes
Contents
# encoding: utf-8 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
96 entries across 96 versions & 1 rubygems