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
11 12 13 14 15 16 17 18 |
# File 'app/controllers/kms/pages_controller.rb', line 11 def create @page = Page.new(page_params) if @page.save render json: @page.to_json else render json: @page.to_json(except: :ancestry, methods: :errors), status: :unprocessable_entity end end |
#destroy ⇒ Object
34 35 36 37 38 |
# File 'app/controllers/kms/pages_controller.rb', line 34 def destroy @page = Page.find(params[:id]) @page.destroy render json: @page.to_json end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/kms/pages_controller.rb', line 6 def index #render json: Page.order("created_at asc").to_json(methods: :parent_id, except: :ancestry) render json: Page.arrange_serializable(order: :position).to_json end |
#show ⇒ Object
29 30 31 32 |
# File 'app/controllers/kms/pages_controller.rb', line 29 def show @page = Page.find(params[:id]) render json: @page.to_json(methods: :parent_id, except: :ancestry) end |
#sorting ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/kms/pages_controller.rb', line 40 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).to_json end |
#update ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/controllers/kms/pages_controller.rb', line 20 def update @page = Page.find(params[:id]) if @page.update_attributes(page_params) render json: @page.to_json else render json: @page.to_json(except: :ancestry, methods: :errors), status: :unprocessable_entity end end |