Class: Handlers::Delegate
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(klass, delegate) ⇒ Delegate
constructor
A new instance of Delegate.
Methods inherited from Base
Constructor Details
#initialize(klass, delegate) ⇒ Delegate
Returns a new instance of Delegate.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/handlers/delegates.rb', line 15 def initialize(klass, delegate) @delegate = delegate @form = @delegate[:form] @foreign_key = @delegate[:foreign_key] @relation = @delegate[:relation] @attributes = @delegate[:attributes] super(klass) end |
Instance Method Details
#handle ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/handlers/delegates.rb', line 26 def handle @attributes = @raw_params.slice(*@attributes.map(&:to_s)).merge({ @foreign_key => @resource.id }) @form.new(@attributes, @resource.send(@relation)).save! @resource.reload end |