app/models/pseud.rb
def change_ownership(creation, pseud, options={})
    creation.pseuds.delete(self)
    creation.pseuds << pseud rescue nil
    if creation.is_a?(Work)
      creation.chapters.each {|chapter| self.change_ownership(chapter, pseud)}
      unless options[:skip_series]
        for series in creation.series
          if series.works.count > 1 && (series.works - [creation]).collect(&:pseuds).flatten.include?(self)
            series.pseuds << pseud rescue nil
          else
            self.change_ownership(series, pseud)
          end
        end
      end
      comments = creation.total_comments.where("comments.pseud_id = ?", self.id)
      comments.each do |comment|
        comment.update_attribute(:pseud_id, pseud.id)
      end
    elsif creation.is_a?(Series) && options[:skip_series]
      creation.works.each {|work| self.change_ownership(work, pseud)}
    end
    # make sure changes affect caching/search/author fields
    creation.save rescue nil
  end
# Change the ownership of a creation from one pseud to another
# Options: skip_series -- if you begin by changing ownership of the series, you don't
# want to go back up again and get stuck in a loop
Change the ownership of a creation from one pseud to another
Options: skip_series -- if you begin by changing ownership of the series, you don't
want to go back up again and get stuck in a loop
Change the ownership of a creation from one pseud to another Options : skip_series -- if you begin by changing ownership of the series you don ' t want to go back up again and get stuck in a loop
def change_ownership(creation, pseud, options={})
    creation.pseuds.delete(self)
    creation.pseuds << pseud rescue nil
    if creation.is_a?(Work)
      creation.chapters.each {|chapter| self.change_ownership(chapter, pseud)}
      unless options[:skip_series]
        for series in creation.series
          if series.works.count > 1 && (series.works - [creation]).collect(&:pseuds).flatten.include?(self)
            series.pseuds << pseud rescue nil
          else
            self.change_ownership(series, pseud)
          end
        end
      end
      comments = creation.total_comments.where("comments.pseud_id = ?", self.id)
      comments.each do |comment|
        comment.update_attribute(:pseud_id, pseud.id)
      end
    elsif creation.is_a?(Series) && options[:skip_series]
      creation.works.each {|work| self.change_ownership(work, pseud)}
    end
    creation.save rescue nil
  end
def change_ownership ( creation , pseud , options = { } ) creation . pseuds . delete ( self ) creation . pseuds << pseud rescue nil if creation . is_a? ( Work ) creation . chapters . each { | chapter | self . change_ownership ( chapter , pseud ) } unless options [ :skip_series ] for series in creation . series if series . works . count > 1 && ( series . works - [ creation ] ) . collect ( & :pseuds ) . flatten . include? ( self ) series . pseuds << pseud rescue nil else self . change_ownership ( series , pseud ) end end end comments = creation . total_comments . where ( "comments.pseud_id = ?" , self . id ) comments . each do | comment | comment . update_attribute ( :pseud_id , pseud . id ) end elsif creation . is_a? ( Series ) && options [ :skip_series ] creation . works . each { | work | self . change_ownership ( work , pseud ) } end creation . save rescue nil end
Change the ownership of a creation from one pseud to another
Options: skip_series -- if you begin by changing ownership of the series, you don't
want to go back up again and get stuck in a loop
Change the ownership of a creation from one pseud to another Options : skip_series -- if you begin by changing ownership of the series you don ' t want to go back up again and get stuck in a loop
# make sure changes affect caching/search/author fields
creation
pseud
options