Class: Api::IngredientsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/alchemy/api/ingredients_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

Returns all ingredients as json object

You can either load all or only these for :element_id or :page_id param



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/alchemy/api/ingredients_controller.rb', line 9

def index
  @ingredients = Alchemy::Ingredient.accessible_by(current_ability, :index)

  if params[:page_id].present?
    @ingredients = @ingredients
      .where(alchemy_page_versions: {page_id: params[:page_id]})
      .merge(Alchemy::PageVersion.drafts)
      .joins(element: :page_version)
  end

  render json: @ingredients, adapter: :json, root: "ingredients"
end