Class: CarrierTypesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /carrier_types POST /carrier_types.json



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

def create
  @carrier_type = CarrierType.new(carrier_type_params)

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

#destroyObject

DELETE /carrier_types/1 DELETE /carrier_types/1.json



96
97
98
99
100
101
102
103
# File 'app/controllers/carrier_types_controller.rb', line 96

def destroy
  @carrier_type.destroy

  respond_to do |format|
    format.html { redirect_to carrier_types_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.carrier_type')) }
    format.json { head :no_content }
  end
end

#editObject

GET /carrier_types/1/edit



54
55
# File 'app/controllers/carrier_types_controller.rb', line 54

def edit
end

#indexObject

GET /carrier_types GET /carrier_types.json



9
10
11
12
13
14
15
16
# File 'app/controllers/carrier_types_controller.rb', line 9

def index
  @carrier_types = CarrierType.order(:position).page(params[:page])

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

#newObject

GET /carrier_types/new GET /carrier_types/new.json



44
45
46
47
48
49
50
51
# File 'app/controllers/carrier_types_controller.rb', line 44

def new
  @carrier_type = CarrierType.new

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

#showObject

GET /carrier_types/1 GET /carrier_types/1.json



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/carrier_types_controller.rb', line 20

def show
  @carrier_type = CarrierType.find(params[:id])
  unless params[:format] == 'download'
    authorize @carrier_type
  end
  if @carrier_type.attachment.path
    if ENV['ENJU_STORAGE'] == 's3'
      file = Faraday.get(@carrier_type.attachment.expiring_url).body.force_encoding('UTF-8')
    else
      file = @carrier_type.attachment.path
    end
  end

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @carrier_type }
    format.download {
      render_image(file)
    }
  end
end

#updateObject

PUT /carrier_types/1 PUT /carrier_types/1.json



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

def update
  if params[:move]
    move_position(@carrier_type, params[:move])
    return
  end

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