Class: Kms::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Kms::PagesController
- Defined in:
- app/controllers/kms/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #sorting ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/controllers/kms/pages_controller.rb', line 10 def create @page = Page.new(page_params) if @page.save head :no_content else render json: { errors: @page.errors. }.to_json, status: :unprocessable_entity end end |
#destroy ⇒ Object
33 34 35 36 37 |
# File 'app/controllers/kms/pages_controller.rb', line 33 def destroy @page = Page.find(params[:id]) @page.destroy head :no_content end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/kms/pages_controller.rb', line 6 def index render json: Page.arrange_serializable(order: :position) end |
#show ⇒ Object
28 29 30 31 |
# File 'app/controllers/kms/pages_controller.rb', line 28 def show @page = Page.find(params[:id]) render json: @page end |
#sorting ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/kms/pages_controller.rb', line 39 def sorting params["_json"].each_with_index do |page, index| p = Page.find_by_id(page["id"]) p.update_attribute(:parent_id, nil) p.update_attribute(:position, index) sort(page["id"], page["children"]) if page["children"].present? end render json: Page.arrange_serializable(order: :position) end |
#update ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/kms/pages_controller.rb', line 19 def update @page = Page.find(params[:id]) if @page.update(page_params) head :no_content else render json: { errors: @page.errors. }.to_json, status: :unprocessable_entity end end |