Class: OwnsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /owns POST /owns.json



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/owns_controller.rb', line 53

def create
  @own = Own.new(own_params)

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

#destroyObject

DELETE /owns/1 DELETE /owns/1.json



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/owns_controller.rb', line 89

def destroy
  @own.destroy

  respond_to do |format|
    format.html {
      flash[:notice] = t('controller.successfully_deleted', model: t('activerecord.models.own'))
      case
      when @agent
        redirect_to agent_owns_url(@agent)
      when @item
        redirect_to item_owns_url(@item)
      else
        redirect_to owns_url
      end
    }
    format.json { head :no_content }
  end
end

#editObject

GET /owns/1/edit



48
49
# File 'app/controllers/owns_controller.rb', line 48

def edit
end

#indexObject

GET /owns GET /owns.json



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

def index
  if @agent
    @owns = @agent.owns.order('owns.position').page(params[:page])
  elsif @item
    @owns = @item.owns.order('owns.position').page(params[:page])
  else
    @owns = Own.page(params[:page])
  end

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

#newObject

GET /owns/new



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/owns_controller.rb', line 33

def new
  if @item && @agent.blank?
    redirect_to item_agents_url(@item)
    return
  elsif @agent && @item.blank?
    redirect_to agent_items_url(@agent)
    return
  else
    @own = Own.new
    @own.item = @item
    @own.agent = @agent
  end
end

#showObject

GET /owns/1 GET /owns/1.json



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

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

#updateObject

PUT /owns/1 PUT /owns/1.json



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

def update
  if @item && params[:move]
    move_position(@own, params[:move], false)
    redirect_to owns_url(item_id: @own.item_id)
    return
  end

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