app/models/taxon_change.rb
# Change all records associated with input taxa to use the selected taxon
Change all records associated with input taxa to use the selected taxon
Change all records associated with input taxa to use the selected taxon
def update_records_of_class(klass, taxon, options = {}, &block)
    if klass.respond_to?(:update_for_taxon_change)
      klass.update_for_taxon_change(self, taxon, options, &block)
      return
    end
    records = if options[:records]
      options[:records]
    else
      scope = klass.send(@klass.name.underscore.pluralize).where("#{klass.table_name}.taxon_id IN (?)", input_taxa).scoped
      scope = scope.where("user_id = ?", options[:user]) if options[:user]
      scope = scope.where(options[:conditions]) if options[:conditions]
      scope = scope.includes(options[:include]) if options[:include]
      scope
    end
    proc = Proc.new do |record|
      record.update_attributes(:taxon => taxon)
      yield(record) if block_given?
    end
    if records.respond_to?(:find_each)
      records.find_each(&proc)
    else
      records.each(&proc)
    end
  end
def update_records_of_class ( klass , taxon , options = { } , & block ) if klass . respond_to? ( :update_for_taxon_change ) klass . update_for_taxon_change ( self , taxon , options , & block ) return end records = if options [ :records ] options [ :records ] else scope = klass . send ( @klass . name . underscore . pluralize ) . where ( "#{klass.table_name}.taxon_id IN (?)" , input_taxa ) . scoped scope = scope . where ( "user_id = ?" , options [ :user ] ) if options [ :user ] scope = scope . where ( options [ :conditions ] ) if options [ :conditions ] scope = scope . includes ( options [ :include ] ) if options [ :include ] scope end proc = Proc . new do | record | record . update_attributes ( :taxon => taxon ) yield ( record ) if block_given? end if records . respond_to? ( :find_each ) records . find_each ( & proc ) else records . each ( & proc ) end end
Change all records associated with input taxa to use the selected taxon
Change all records associated with input taxa to use the selected taxon
klass
taxon
options
block