vendredi 26 novembre 2021

How to include a if condition inside where clause in rails

I have the following method:

def add_books(year, industry, author_id=nil)
  Books.where(publication_year:year, author: author_id)
end

How can I update the query to not filter by author_id if it is not passed?

Aucun commentaire:

Enregistrer un commentaire