Sha256: cafb7f45010ab384ce9bafa64b3c9799e89118b978887a3e6e7afb902dabecd2

Contents?: true

Size: 1.29 KB

Versions: 28

Compression:

Stored size: 1.29 KB

Contents

class MergesController < ArtfullyOseController
  def new
    @loser = Person.find(params[:loser])
    without_winner do
      if is_search(params)
        @people = Person.search_index(params[:search].dup, current_user.current_organization)
      else
        @people = Person.recent(current_user.current_organization)
      end
      @people = @people.reject { |person| person.id == @loser.id }
      @people = @people.reject { |person| person.type != @loser.type }
      @people = @people.paginate(:page => params[:page], :per_page => 20)
      render :find_person
    end
  end
  
  def create
    @winner = Person.find(params[:winner])
    @loser = Person.find(params[:loser])
    if @winner.type == @loser.type
      @result = Person.merge(@winner, @loser)
      flash[:notice] = "#{@loser} has been merged into this record"
      redirect_to person_path(:id => @winner.id)
    else
      flash[:error] = "Both records must be the same time. A company cannot merge with an individual."
      redirect_to new_merge_path(:loser => @person)
    end
  end

  private    
    def is_search(params)
      params[:commit].present?
    end    
    
    def without_winner
      if params[:winner]
        @winner = Person.find(params[:winner])
        render :new and return
      else
        yield
      end
    end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/controllers/merges_controller.rb
artfully_ose-1.2.0.beta.1 app/controllers/merges_controller.rb
artfully_ose-1.2.0.alpha.2 app/controllers/merges_controller.rb
artfully_ose-1.2.0.alpha.1 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.27 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.26 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.24 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.23 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.21 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.20 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.19 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.18 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.17 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.16 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.15 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.12 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.11 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.10 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.9 app/controllers/merges_controller.rb
artfully_ose-1.2.0.pre.8 app/controllers/merges_controller.rb