Class: Api::PagesController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::PagesController
- Defined in:
- app/controllers/alchemy/api/pages_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
Returns all pages as json object.
- #move ⇒ Object
-
#nested ⇒ Object
Returns all pages as nested json object for tree views.
-
#show ⇒ Object
Returns a json object for page.
Instance Method Details
#index ⇒ Object
Returns all pages as json object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/alchemy/api/pages_controller.rb', line 10 def index @pages = Alchemy::Page.accessible_by(current_ability, :index) @pages = @pages.includes(*page_includes) @pages = @pages.ransack(params[:q]).result if params[:page] @pages = @pages.page(params[:page]).per(params[:per_page]) end render json: @pages, adapter: :json, root: "pages", meta: end |
#move ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/alchemy/api/pages_controller.rb', line 49 def move @page = Page.find(params[:id]) :update, @page begin target_parent_page = Page.find(params[:target_parent_id]) @page.move_to_child_with_index(target_parent_page, params[:new_position]) render json: @page, serializer: PageNodeSerializer rescue => err render json: {message: err.}, status: 422 end end |
#nested ⇒ Object
Returns all pages as nested json object for tree views
Pass a page_id param to only load tree for this page
Pass elements=true param to include elements for pages
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/alchemy/api/pages_controller.rb', line 28 def nested @page = Page.find_by(id: params[:page_id]) || Language.current_root_page render json: PageTreeSerializer.new( @page, ability: current_ability, user: current_alchemy_user, elements: params[:elements], full: true ) end |
#show ⇒ Object
Returns a json object for page
You can either load the page via id or its urlname
44 45 46 47 |
# File 'app/controllers/alchemy/api/pages_controller.rb', line 44 def show :show, @page render json: @page, serializer: PageSerializer end |