class IngredientsController < ApplicationController def search @ingredients = Food.search(params[:query]).order(:name).to_a @ingredients.concat(Recipe.is_ingredient.search_by_name(params[:query]).order(:name).to_a) @ingredients.sort { |a, b| a.name <=> b.name } json = @ingredients.map do |i| { id: i.ingredient_id, ingredient_id: i.ingredient_id, name: i.name, density: i.density } end render json: json end end