Class: RiddlerAdmin::ElementsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/riddler_admin/elements_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /elements



18
19
20
21
22
23
24
25
26
# File 'app/controllers/riddler_admin/elements_controller.rb', line 18

def create
  @element = @element_class.new element_create_params

  if @element.save
    render :show
  else
    render :new
  end
end

#destroyObject

DELETE /elements/1



38
39
40
41
# File 'app/controllers/riddler_admin/elements_controller.rb', line 38

def destroy
  @element.destroy
  render :destroy
end

#newObject

GET /elements/new



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

def new
  hash = {}
  if step = Step.find_by_id(params["step_id"])
    hash[:container] = step
  end
  @element = @element_class.new hash
end

#sortObject

PUT /elements/sort



44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/riddler_admin/elements_controller.rb', line 44

def sort
  element_order = params.fetch "element_order"

  element_order.each_with_index do |element_id, index|
    element = Element.find_by_id element_id
    element.update_attribute :position, index+1
  end

  head :no_content
end

#updateObject

PATCH/PUT /elements/1



29
30
31
32
33
34
35
# File 'app/controllers/riddler_admin/elements_controller.rb', line 29

def update
  if @element.update element_params
    redirect_to @element, notice: 'Element was successfully updated.'
  else
    render :edit
  end
end