Class: Admin::ElementsController
- Inherits:
-
AdminController
- Object
- ApplicationController
- AdminController
- Admin::ElementsController
- Defined in:
- app/controllers/admin/elements_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /elements or /elements.json Creates a new element with the provided parameters.
-
#destroy ⇒ Object
DELETE /elements/1 or /elements/1.json Deletes a specific element.
-
#edit ⇒ Object
GET /elements/1/edit Prepares an element for editing.
-
#index ⇒ Object
GET /elements or /elements.json Lists all elements, ordered by position in ascending order.
-
#new ⇒ Object
GET /elements/new Initializes a new element object.
-
#show ⇒ Object
GET /elements/1 or /elements/1.json Displays a specific element.
-
#sort ⇒ Object
POST /elements/sort Sorts elements based on the provided list of IDs.
-
#update ⇒ Object
PATCH/PUT /elements/1 or /elements/1.json Updates an existing element with the provided parameters.
Instance Method Details
#create ⇒ Object
POST /elements or /elements.json Creates a new element with the provided parameters. If successful, redirects to the element’s show page with a success notice. If unsuccessful, re-renders the new element form with error messages.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/admin/elements_controller.rb', line 38 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 |
#destroy ⇒ Object
DELETE /elements/1 or /elements/1.json Deletes a specific element. Redirects to the elements index page with a success notice.
71 72 73 74 75 76 77 78 |
# File 'app/controllers/admin/elements_controller.rb', line 71 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 |
#edit ⇒ Object
GET /elements/1/edit Prepares an element for editing.
31 32 |
# File 'app/controllers/admin/elements_controller.rb', line 31 def edit end |
#index ⇒ Object
GET /elements or /elements.json Lists all elements, ordered by position in ascending order. Uses pagination to limit the number of elements displayed per page.
14 15 16 |
# File 'app/controllers/admin/elements_controller.rb', line 14 def index @elements = Element.all.order(position: :asc) end |
#new ⇒ Object
GET /elements/new Initializes a new element object.
25 26 27 |
# File 'app/controllers/admin/elements_controller.rb', line 25 def new @element = Element.new end |
#show ⇒ Object
GET /elements/1 or /elements/1.json Displays a specific element.
20 21 |
# File 'app/controllers/admin/elements_controller.rb', line 20 def show end |
#sort ⇒ Object
POST /elements/sort Sorts elements based on the provided list of IDs. Renders an empty response body.
83 84 85 86 |
# File 'app/controllers/admin/elements_controller.rb', line 83 def sort Element.sort_elements(params[:id_list]) render body: nil end |
#update ⇒ Object
PATCH/PUT /elements/1 or /elements/1.json Updates an existing element with the provided parameters. If successful, redirects to the element’s show page with a success notice. If unsuccessful, re-renders the edit form with error messages.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/admin/elements_controller.rb', line 56 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 |