# Searching problem!

**URL:** <https://www.ruby-forum.com/t/searching-problem/145275>\
**Category:** Rails\
**Created:** [August 7, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/searching-problem/145275 "2008-08-07T13:16:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 7, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/searching-problem/145275/1 "2008-08-07T13:16:35Z")

</div>

Hi , i have customize function for search text. in controller

CONTROLLER\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

def search

```
if (query = params[:q] )
      @postjob = Postjob.find(:all, :conditions => ["company_name =

```

?", query])

```
 end

```

* * *

VIEW\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

\<%= link\_to "Post Job" , :action =\> "new"%\> &nbsp; Employers place new openings &nbsp;&nbsp; \<%= start\_form\_tag :action=\>'search\_by\_country'%\> \<%= text\_field 'co' ,nil %\> \<%= submit\_tag "Find Country" , :controller =\> "postjobs" , :action =\> "serach\_by\_country"%\> \<%= end\_form\_tag%\>

# Listing jobs by Country

\<% else if @postjob !=nil %\>

\<%= link\_to "#{p.country}", :action =\> 'list', :id =\> p%\> &nbsp;\<%= p.headline.capitalize%\>,&nbsp; \<%=p.company\_name.capitalize%\>

\<%end%\>

|
| |

\<%else%\>

#### No Match Found ! Try with different keywords.....

\<% end %\> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

I can search text and i am getting desired result .Now main thing is  
that when i search for blank text box i want to show message

#### No Match Found ! Try with different keywords…
 or if i enter wrong  
key work and search result comes nothing i want to print message no data  
found …  
i tried lot with different conditions but i am not getting proper result  
.

Please help me !

Thanks in advance.  
🙂

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 7, 2008, 1:33pm UTC](https://www.ruby-forum.com/t/searching-problem/145275/2 "2008-08-07T13:33:43Z")

</div>

On Aug 7, 12:16 pm, Dharmdip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I can search text and i am getting desired result .Now main thing is  
> that when i search for blank text box i want to show message
> 
> #### No Match Found ! Try with different keywords…
> or if i enter wrong  
> key work and search result comes nothing i want to print message no data  
> found …  
> i tried lot with different conditions but i am not getting proper result  
> .

@postjob will never be nil. find :all, always returns an array (which  
may or may not be empty)

Fred
