title: How to require a value is entered in a search form
body: <p>I built a basic search form that queries one column in one table of my app. I followed episode 37 Railscast: <a href="http://railscasts.com/episodes/37-simple-search-form" rel="nofollow noreferrer">http://railscasts.com/episodes/37-simple-search-form</a>.  Note I just posted another search related question, but it's on a completely different issue.</p>
  
  <p>In my app, the search queries the zip code column of my profile table, and returns a list of profiles that contain the right zip code. </p>
  
  <p>Here's my problem. Currently, when a user leaves the input blank and hits the submit button, the search displays all profiles on the site.  I don't want this to happen.  If the field is blank, I don't want the search to go through.  I'd like to either do a flash notice or throw an error, explaining that the user needs to enter a zip code to proceed.</p>
  
  <p>Here's my setup:</p>
  
  <p>PROFILES CONTROLLER</p>
  
  <pre><code>def index  
      @profiles = Profile.search(params[:search])  
  end
  </code></pre>
  
  <p>PROFILE MODEL</p>
  
  <pre><code>def self.search(search)
          if search
                  find(:all, :conditions =&gt; ['zip LIKE ?', "%#{search}%"])
          else
                  find(:all)
          end
  end
  </code></pre>
  
  <p>PROFILE/INDEX.HTML.ERB</p>
  
  <pre><code>&lt;% form_tag ('/profiles', :method =&gt; :get) do %&gt;
      &lt;%= text_field_tag :search, params[:search], :maxlength =&gt; 5 %&gt;
      &lt;%= submit_tag "Go", :name =&gt; nil %&gt;                
  &lt;% end %&gt;
  </code></pre>
  
  <p>Thanks!</p>