# Search logic doubt.plz help

**URL:** <https://www.ruby-forum.com/t/search-logic-doubt-plz-help/191307>\
**Category:** Rails\
**Created:** [July 9, 2010, 1:19pm UTC](https://www.ruby-forum.com/t/search-logic-doubt-plz-help/191307 "2010-07-09T13:19:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nazimzeeshan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/77aa72/32.png) [@nazimzeeshan](https://www.ruby-forum.com/u/nazimzeeshan)\
**Post date:** [July 9, 2010, 1:19pm UTC](https://www.ruby-forum.com/t/search-logic-doubt-plz-help/191307/1 "2010-07-09T13:19:32Z")

</div>

i am having some products in a database(mysql) n i have done the  
scaffolding and added a search.

So when i search, if product found then it shud display it and if not  
found it shud redirect to create page.

Here is d controller code for find i used

* * *

def find

@products=Product.find(:all, :conditions =\> [“item LIKE  
?”,params[:search\_string]])

end

* * *

and in ‘find.html.erb’

* * *

\<% if @products.blank? %\>

EMPTY

 # what code shud I enter here so as to redirect to create page?? \<% else %\> \<% end %\> \<% for review in @reviews %\>
## Listing Products for \<%= params[:search\_string].capitalize%\>
......................so on. \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

So i want to know how to redirect to create page and where shud d code  
be written. In view or controller.? and what code shud be used to  
implement redirection.

So plz som1 help.  
Nazim Zeeshan,India

---

<div class="post-metadata">

**Author:** ![nazimzeeshan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/77aa72/32.png) [@nazimzeeshan](https://www.ruby-forum.com/u/nazimzeeshan)\
**Post date:** [July 9, 2010, 1:33pm UTC](https://www.ruby-forum.com/t/search-logic-doubt-plz-help/191307/2 "2010-07-09T13:33:59Z")

</div>

On 9 July 2010 12:19, Zeeshan N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @products=Product.find(:all, :conditions =\> [“item LIKE  
> ?”,params[:search\_string]])

Test for @products.count == 0 here and use redirect\_to to go the  
appropriate action

Colin
