Class: RiddlerAdmin::ElementsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RiddlerAdmin::ElementsController
- Defined in:
- app/controllers/riddler_admin/elements_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /elements.
-
#destroy ⇒ Object
DELETE /elements/1.
-
#new ⇒ Object
GET /elements/new.
-
#sort ⇒ Object
PUT /elements/sort.
-
#update ⇒ Object
PATCH/PUT /elements/1.
Methods inherited from ApplicationController
#riddler_current_user, #riddler_user_can_approve?, #riddler_user_can_deploy?
Instance Method Details
#create ⇒ Object
POST /elements
22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/riddler_admin/elements_controller.rb', line 22 def create @element = @element_class.new element_create_params if @element.save render :show else render :new end end |
#destroy ⇒ Object
DELETE /elements/1
42 43 44 45 |
# File 'app/controllers/riddler_admin/elements_controller.rb', line 42 def destroy @element.destroy render :destroy end |
#new ⇒ Object
GET /elements/new
9 10 11 12 13 14 15 16 17 18 19 |
# 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 elsif element = RiddlerAdmin::Element.find_by_id(params[:element_id]) hash[:container] = element end @element = @element_class.new hash end |
#sort ⇒ Object
PUT /elements/sort
48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/riddler_admin/elements_controller.rb', line 48 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 |
#update ⇒ Object
PATCH/PUT /elements/1
33 34 35 36 37 38 39 |
# File 'app/controllers/riddler_admin/elements_controller.rb', line 33 def update if @element.update element_params redirect_to @element, notice: 'Element was successfully updated.' else render :edit end end |