Class: ProducesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /produces POST /produces.json



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/produces_controller.rb', line 60

def create
  @produce = Produce.new(produce_params)

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

#destroyObject

DELETE /produces/1 DELETE /produces/1.json



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/produces_controller.rb', line 98

def destroy
  @produce.destroy

  respond_to do |format|
    format.html {
      flash[:notice] = t('controller.successfully_deleted', model: t('activerecord.models.produce'))
      case
      when @agent
        redirect_to agent_manifestations_url(@agent)
      when @manifestation
        redirect_to manifestation_agents_url(@manifestation)
      else
        redirect_to produces_url
      end
    }
    format.json { head :no_content }
  end
end

#editObject

GET /produces/1/edit



55
56
# File 'app/controllers/produces_controller.rb', line 55

def edit
end

#indexObject

GET /produces GET /produces.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/produces_controller.rb', line 9

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

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @produces }
  end
#rescue
#  respond_to do |format|
#    format.html { render action: "new" }
#    format.json { render json: @produce.errors, status: :unprocessable_entity }
#  end
end

#newObject

GET /produces/new



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/produces_controller.rb', line 40

def new
  if @agent && @manifestation.blank?
    redirect_to agent_manifestations_url(@agent)
    return
  elsif @manifestation && @agent.blank?
    redirect_to manifestation_agents_url(@manifestation)
    return
  else
    @produce = Produce.new
    @produce.manifestation = @manifestation
    @produce.agent = @agent
  end
end

#showObject

GET /produces/1 GET /produces/1.json



32
33
34
35
36
37
# File 'app/controllers/produces_controller.rb', line 32

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

#updateObject

PUT /produces/1 PUT /produces/1.json



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/produces_controller.rb', line 77

def update
  if @manifestation && params[:move]
    move_position(@produce, params[:move], false)
    redirect_to produces_url(manifestation_id: @produce.manifestation_id)
    return
  end

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