Class: AgentMergeListsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/agent_merge_lists_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /agent_merge_lists POST /agent_merge_lists.json



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/agent_merge_lists_controller.rb', line 42

def create
  @agent_merge_list = AgentMergeList.new(agent_merge_list_params)

  respond_to do |format|
    if @agent_merge_list.save
      flash[:notice] = t('controller.successfully_created', model: t('activerecord.models.agent_merge_list'))
      format.html { redirect_to(@agent_merge_list) }
      format.json { render json: @agent_merge_list, status: :created, location: @agent_merge_list }
    else
      format.html { render action: "new" }
      format.json { render json: @agent_merge_list.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /agent_merge_lists/1 DELETE /agent_merge_lists/1.json



86
87
88
89
90
91
92
93
# File 'app/controllers/agent_merge_lists_controller.rb', line 86

def destroy
  @agent_merge_list.destroy

  respond_to do |format|
    format.html { redirect_to(agent_merge_lists_url) }
    format.json { head :no_content }
  end
end

#editObject

GET /agent_merge_lists/1/edit



37
38
# File 'app/controllers/agent_merge_lists_controller.rb', line 37

def edit
end

#indexObject

GET /agent_merge_lists GET /agent_merge_lists.json



7
8
9
10
11
12
13
14
# File 'app/controllers/agent_merge_lists_controller.rb', line 7

def index
  @agent_merge_lists = AgentMergeList.page(params[:page])

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @agent_merge_lists }
  end
end

#newObject

GET /agent_merge_lists/new GET /agent_merge_lists/new.json



27
28
29
30
31
32
33
34
# File 'app/controllers/agent_merge_lists_controller.rb', line 27

def new
  @agent_merge_list = AgentMergeList.new

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @agent_merge_list }
  end
end

#showObject

GET /agent_merge_lists/1 GET /agent_merge_lists/1.json



18
19
20
21
22
23
# File 'app/controllers/agent_merge_lists_controller.rb', line 18

def show
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @agent_merge_list }
  end
end

#updateObject

PUT /agent_merge_lists/1 PUT /agent_merge_lists/1.json



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/agent_merge_lists_controller.rb', line 59

def update
  respond_to do |format|
    if @agent_merge_list.update(agent_merge_list_params)
      if params[:mode] == 'merge'
        selected_agent = Agent.where(id: params[:selected_agent_id]).first
        if selected_agent
          @agent_merge_list.merge_agents(selected_agent)
          flash[:notice] = t('merge_list.successfully_merged', model: t('activerecord.models.agent'))
        else
          flash[:notice] = t('merge_list.specify_id', model: t('activerecord.models.agent'))
          redirect_to agent_merge_list_url(@agent_merge_list)
          return
        end
      else
        flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.agent_merge_list'))
      end
      format.html { redirect_to(@agent_merge_list) }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @agent_merge_list.errors, status: :unprocessable_entity }
    end
  end
end