parsley/app/controllers/ingredients_controller.rb

20 lines
500 B
Ruby
Raw Normal View History

2018-09-12 09:43:50 -05:00
class IngredientsController < ApplicationController
def search
@ingredients = Food.search(params[:query]).order(:name).to_a
2018-09-12 14:17:18 -05:00
@ingredients.concat(Recipe.is_ingredient.search_by_name(params[:query]).order(:name).to_a)
2018-09-12 09:43:50 -05:00
@ingredients.sort { |a, b| a.name <=> b.name }
2020-08-07 12:33:06 -05:00
json = @ingredients.map do |i|
{
id: i.ingredient_id,
ingredient_id: i.ingredient_id,
name: i.name,
density: i.density
}
end
2018-09-12 09:43:50 -05:00
2020-08-07 12:33:06 -05:00
render json: json
end
end