Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/plugins/in_place_editing/lib/in_place_editing.rb

Revision 7782, 0.6 kB (checked in by bitsweat, 1 year ago)

Fix setter action with non-string fields. References #7418.

Line 
1 module InPlaceEditing
2   def self.included(base)
3     base.extend(ClassMethods)
4   end
5
6   # Example:
7   #
8   #   # Controller
9   #   class BlogController < ApplicationController
10   #     in_place_edit_for :post, :title
11   #   end
12   #
13   #   # View
14   #   <%= in_place_editor_field :post, 'title' %>
15   #
16   module ClassMethods
17     def in_place_edit_for(object, attribute, options = {})
18       define_method("set_#{object}_#{attribute}") do
19         @item = object.to_s.camelize.constantize.find(params[:id])
20         @item.update_attribute(attribute, params[:value])
21         render :text => @item.send(attribute).to_s
22       end
23     end
24   end
25 end
Note: See TracBrowser for help on using the browser.