Class: ForestLiana::BelongsToUpdater
- Inherits:
-
Object
- Object
- ForestLiana::BelongsToUpdater
- Defined in:
- app/services/forest_liana/belongs_to_updater.rb
Instance Method Summary collapse
-
#initialize(resource, association, params) ⇒ BelongsToUpdater
constructor
A new instance of BelongsToUpdater.
- #perform ⇒ Object
Constructor Details
#initialize(resource, association, params) ⇒ BelongsToUpdater
Returns a new instance of BelongsToUpdater.
3 4 5 6 7 8 |
# File 'app/services/forest_liana/belongs_to_updater.rb', line 3 def initialize(resource, association, params) @resource = resource @association = association @params = params @data = params['data'] end |
Instance Method Details
#perform ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/services/forest_liana/belongs_to_updater.rb', line 10 def perform @record = @resource.find(@params[:id]) new_value = @association.klass.find(@data[:id]) if @data && @data[:id] @record.send("#{@association.name}=", new_value) @record.save() end |