Class: Trade::Admin::PromotesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/trade/admin/promotes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/trade/admin/promotes_controller.rb', line 21

def create
  @promote = Promote.new(promote_params)
  
  if @promote.save
    @promote_charge = @promote.promote_charges.build
  else
    render :new, locals: { model: @promote }, status: :unprocessable_entity
  end
end

#destroyObject



45
46
47
# File 'app/controllers/trade/admin/promotes_controller.rb', line 45

def destroy
  @promote.destroy
end

#editObject



34
35
# File 'app/controllers/trade/admin/promotes_controller.rb', line 34

def edit
end

#indexObject



4
5
6
7
8
9
10
# File 'app/controllers/trade/admin/promotes_controller.rb', line 4

def index
  q_params = {}
  q_params.merge! default_params
  q_params.merge! params.permit(:scope)
  
  @promotes = Promote.default_where(q_params).order(id: :desc).page(params[:page])
end

#newObject



17
18
19
# File 'app/controllers/trade/admin/promotes_controller.rb', line 17

def new
  @promote = Promote.new
end

#searchObject



12
13
14
15
# File 'app/controllers/trade/admin/promotes_controller.rb', line 12

def search
  @promotes = Promote.default_where('name-like': params[:q])
  render json: { results: @promotes.as_json(only: [:id, :name]) }
end

#showObject



31
32
# File 'app/controllers/trade/admin/promotes_controller.rb', line 31

def show
end

#updateObject



37
38
39
40
41
42
43
# File 'app/controllers/trade/admin/promotes_controller.rb', line 37

def update
  @promote.assign_attributes promote_params

  unless @promote.save
    render :edit, locals: { model: @promote }, status: :unprocessable_entity
  end
end