Sha256: 1732eaef7dac0db39461a2b654bdb26acc3f5e05d5aa1e1f17b956cfb9024587
Contents?: true
Size: 1.06 KB
Versions: 25
Compression:
Stored size: 1.06 KB
Contents
module ForestLiana class BelongsToUpdater attr_accessor :errors def initialize(resource, association, params) @resource = resource @association = association @params = params @data = params['data'] @errors = nil end def perform begin @record = @resource.find(@params[:id]) if (SchemaUtils.polymorphic?(@association)) if @data.nil? new_value = nil else association_klass = SchemaUtils.polymorphic_models(@association).select { |a| a.name.downcase == @data[:type] }.first new_value = association_klass.find(@data[:id]) if @data && @data[:id] end else new_value = @association.klass.find(@data[:id]) if @data && @data[:id] end @record.send("#{@association.name}=", new_value) @record.save rescue ActiveRecord::SerializationTypeMismatch => exception @errors = [{ detail: exception.message }] rescue => exception @errors = [{ detail: exception.message }] end end end end
Version data entries
25 entries across 25 versions & 1 rubygems