I have Article and Category, with a has_and_belongs_to_many relation between the two.I want to use Article.in_categories(category_ids) to get any Article that is in any of the category_ids passed, and I want to handle the possibility of category_ids being nil in a way that all Article items are returned. The category_ids value is coming from a form, and I want the user to be able to ignore the Category selection part of the form if they do not want to limit their selection by that criteria.I currently have this in place on the Article model:def self.in_categories(category_ids = nil)  category_ids.blank? ? all : includes(:categories).where(categories: { id: category_ids })endIf I do not have the check for category_ids being nil, then it will only return the Article items that are not in any Category.I do not want to manually set category_ids = [1,2,3] (for example) in the method call, because a Category can be added/removed.Is there a better way of handling this than the way I already do?
Searching has_and_belongs_to_many relations for article categories
ruby;ruby on rails