Reputation:
I am attempting to render a search_failed
page in case a product is not found.
Line #4 shows an error.
Here's my code:
def search
if (params[:search]).present?
@products = Product.search(params[:search])
unless @products = Product.search(params[:search]).!present?
render 'search_failed'
end
else
render 'search_failed'
end
end
Upvotes: 0
Views: 30
Reputation: 2872
Try something like this (you are calling the search twice in your example)
def search
if (params[:search]).present?
@products = Product.search(params[:search])
if @products.empty?
render 'search_failed'
end
else
render 'search_failed'
end
end
Upvotes: 1