class Api::SearchController < ApplicationController
  def show
    lines = Line.search(params[:term]).joins(:quote)
    if lines.any?
      render json: lines.map(&:quote)
    else
      render json: Quote.random
    end
  end
end

class Api::SearchController < ApplicationController
  def show
    @search = Line.search(params[:term]).joins(:quote).includes(:character, :quote).map(&:quote)
    render json: @search
  end
end

Simplify search and eager load associations
Simplify search and eager load associations
