Reputation: 26061
I'm trying to filter the results that are returned from my index view based on optional params. My code is working for the first param, sinceDate. But for the second param, searchQeury, nothing is filtered out.
_controller.rb
def index
since = params[:sinceDate]
query = params[:searchQuery]
@articles = Comfy::Cms::Page.published.all
if since
@articles = @articles.reject{ |a| a[:created_at] < Date.parse(since) }
end
if query
@article = @articles.select{ |a| a[:label].match(/#{query}/i) }
end
end
Upvotes: 0
Views: 91
Reputation: 81
Is it possible that the problem is a typo? In the line after "if query", it should be perhaps @articles instead of @article.
Upvotes: 1