user4932805
user4932805

Reputation:

search definition in rails

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

Answers (1)

bo-oz
bo-oz

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

Related Questions