Sha256: 72ce0d334e810d6cd88a6aa4e5a0e49f9cc6f5c8b11800a35dac56c870cac536

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Alchemy
  class Api::ContentsController < Api::BaseController
    # Returns all contents as json object
    #
    # You can either load all or only these for :element_id param
    #
    def index
      @contents = Content.accessible_by(current_ability, :index)
      if params[:element_id].present?
        @contents = @contents.where(element_id: params[:element_id])
      end
      respond_with @contents
    end

    # Returns a json object for content
    #
    # You can either load it from :id param
    # or even more useful via passing the element id and the name of the content
    #
    #   $ bin/rake routes
    #
    # for more infos on how the url looks like.
    #
    def show
      if params[:id]
        @content = Content.find(params[:id])
      elsif params[:element_id] && params[:name]
        @content = Content.find_by!(element_id: params[:element_id], name: params[:name])
      end
      authorize! :show, @content
      respond_with @content
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-4.0.6 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.5 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.4 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.3 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.2 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.1 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.0 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.0.rc2 app/controllers/alchemy/api/contents_controller.rb
alchemy_cms-4.0.0.rc1 app/controllers/alchemy/api/contents_controller.rb