Module: Refinery::Widgets::ActsAsWidget::ClassMethods

Defined in:
lib/refinery/widgets/acts_as_widget.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_widget(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/refinery/widgets/acts_as_widget.rb', line 11

def acts_as_widget(options={})
  widget_type = WidgetType.find(self.to_s)
  self.class_eval do
    belongs_to :widget, class_name: 'Refinery::Widgets::Widget'
    ApplicationController.class_eval do
      define_method widget_type.association_name, Proc.new{}
    end
  end
  Widget.class_eval do
    has_one widget_type.association_name.to_sym, class_name: widget_type.klass_as_string, dependent: :destroy
    accepts_nested_attributes_for widget_type.association_name.to_sym
  end
end