Hi I have a model books with below mentioned method:
def self.text_search(query)
pry
if query.present?
where("title @@ :q or author @@ :q", q: query)
else
find(-1)
end
end
In my controller, I send respond to client as JSON:
render json: @books
This code works fine if the query returns something. If not, I am not able to send a JSON response. I get a template missint error.
How can I handle it in JSON?
I tried
class BooksController < ApplicationController
def index
@books = Book.text_search(params[:query])
@author= Author.find(Shelf.find(@books.map(&:isbn).uniq).map(&:author_id))
rescue ActiveRecord::RecordNotFound #donothing
render json: @books
end
end