public
Description: Easy editing in place for RESTful web apps.
Homepage:
Clone URL: git://github.com/nakajima/better-edit-in-place.git
Szymon Nowak (author)
Wed Jan 21 07:54:10 -0800 2009
nakajima (committer)
Wed Jan 21 13:56:00 -0800 2009
100644 23 lines (18 sloc) 0.766 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Nakajima
  module BetterEditInPlace
    def edit_in_place(resource, field, options={})
      # Get record to be edited. If resource is an array, pull it out.
      record = resource.is_a?(Array) ? resource.last : resource
 
      options[:id] ||= "#{dom_id(record)}_#{field}"
      options[:tag] ||= :span
      options[:url] ||= url_for(resource)
      options[:rel] ||= options.delete(:url)
      options.delete(:url) # Just in case it wasn't cleared already
 
      classes = options[:class].split(' ') rescue []
      classes << 'editable' if classes.empty?
      options[:class] = classes.uniq.join(' ')
 
      content_tag(options.delete(:tag), record.send(field), options)
    end
  end
end
 
ActionView::Base.send :include, Nakajima::BetterEditInPlace