Class: AgentRelationshipsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /agent_relationships POST /agent_relationships.json



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/agent_relationships_controller.rb', line 49

def create
  @agent_relationship = AgentRelationship.new(agent_relationship_params)

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

#destroyObject

DELETE /agent_relationships/1 DELETE /agent_relationships/1.json



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/agent_relationships_controller.rb', line 88

def destroy
  @agent_relationship.destroy

  respond_to do |format|
    format.html {
      flash[:notice] = t('controller.successfully_deleted', model: t('activerecord.models.agent_relationship'))
      if @agent
        redirect_to agents_url(agent_id: @agent.id)
      else
        redirect_to agent_relationships_url
      end
    }
    format.json { head :no_content }
  end
end

#editObject

GET /agent_relationships/1/edit



44
45
# File 'app/controllers/agent_relationships_controller.rb', line 44

def edit
end

#indexObject

GET /agent_relationships GET /agent_relationships.json



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/agent_relationships_controller.rb', line 9

def index
  case
  when @agent
    @agent_relationships = @agent.agent_relationships.order('agent_relationships.position').page(params[:page])
  else
    @agent_relationships = AgentRelationship.page(params[:page])
  end

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

#newObject

GET /agent_relationships/new



33
34
35
36
37
38
39
40
41
# File 'app/controllers/agent_relationships_controller.rb', line 33

def new
  if @agent.blank?
    redirect_to agents_url
    return
  else
    @agent_relationship = AgentRelationship.new
    @agent_relationship.agent = @agent
  end
end

#showObject

GET /agent_relationships/1 GET /agent_relationships/1.json



25
26
27
28
29
30
# File 'app/controllers/agent_relationships_controller.rb', line 25

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

#updateObject

PUT /agent_relationships/1 PUT /agent_relationships/1.json



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/agent_relationships_controller.rb', line 66

def update
  # 並べ替え
  if @agent && params[:move]
    move_position(@agent_relationship, params[:move], false)
    redirect_to agent_relationships_url(agent_id: @agent_relationship.parent_id)
    return
  end

  respond_to do |format|
    if @agent_relationship.update(agent_relationship_params)
      format.html { redirect_to @agent_relationship, notice: t('controller.successfully_updated', model: t('activerecord.models.agent_relationship')) }
      format.json { head :no_content }
    else
      prepare_options
      format.html { render action: "edit" }
      format.json { render json: @agent_relationship.errors, status: :unprocessable_entity }
    end
  end
end