Class: Admin::ElementsController

Inherits:
AdminController show all
Defined in:
app/controllers/admin/elements_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /elements or /elements.json



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/elements_controller.rb', line 27

def create
  @element = Element.new(element_params)

  respond_to do |format|
    if @element.save
      format.html { redirect_to admin_element_url(@element), notice: "Element was successfully created." }
      format.json { render :show, status: :created, location: @element }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @element.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /elements/1 or /elements/1.json



55
56
57
58
59
60
61
62
# File 'app/controllers/admin/elements_controller.rb', line 55

def destroy
  @element.destroy

  respond_to do |format|
    format.html { redirect_to admin_elements_url, notice: "Element was successfully destroyed." }
    format.json { head :no_content }
  end
end

#editObject

GET /elements/1/edit



23
24
# File 'app/controllers/admin/elements_controller.rb', line 23

def edit
end

#indexObject

GET /elements or /elements.json



9
10
11
# File 'app/controllers/admin/elements_controller.rb', line 9

def index
  @pagy, @elements = pagy(Element.all.order(position: :asc), items: 100)
end

#newObject

GET /elements/new



18
19
20
# File 'app/controllers/admin/elements_controller.rb', line 18

def new
  @element = Element.new
end

#showObject

GET /elements/1 or /elements/1.json



14
15
# File 'app/controllers/admin/elements_controller.rb', line 14

def show
end

#sortObject



64
65
66
67
# File 'app/controllers/admin/elements_controller.rb', line 64

def sort
  Element.sort_elements(params[:id_list])
  render body: nil
end

#updateObject

PATCH/PUT /elements/1 or /elements/1.json



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

def update
  respond_to do |format|
    if @element.update(element_params)
      format.html { redirect_to admin_element_url(@element), notice: "Element was successfully updated." }
      format.json { render :show, status: :ok, location: @element }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @element.errors, status: :unprocessable_entity }
    end
  end
end