title: searching from the main page in Rails
body: <p>I am working on my first web and Rails app and can not figure out how to get a search feature work from my main page to one of the controllers.</p>
  
  <p>How to send the request and redirect to a results page to show the results from the search.
  I can't get this to work as am not sure how to route in a way my variable @histories will keep results and display on the show page.</p>
  
  <p>I would appreciate some insight into search from any page and displaying results on a dedicated page.</p>
  
  <p>Here is what i have so far in terms of the controller, model and partials.</p>
  
  <h1>Shipments Model:</h1>
  
  <pre><code>def self.search(search)
      search_condition = search
      find_by_sql("SELECT cargo_transit_histories.current_location,cargo_transit_histories.updated_at     FROM cargo_transit_histories
  INNER JOIN shipments ON shipments.id = cargo_transit_histories.shipment_id WHERE  shipments.tracking_number='search_condition'")
  end
  </code></pre>
  
  <h1>Tracking Controller:</h1>
  
  <pre><code>def search
    @histories = Shipment.search(params[:search])
    render('show')
  end
  </code></pre>
  
  <h1>Show (Found in Tracking view):</h1>
  
  <pre><code>&lt;div class="search_result"&gt;
  &lt;%= render 'track/search_results' %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h1>_search (partial):</h1>
  
  <pre><code>&lt;%= form_tag :controller =&gt; 'tracking', :action =&gt; 'search', :method =&gt; 'get' do %&gt;
    &lt;%= text_field_tag :search, params[:search], :id =&gt; 'search_field' %&gt;
    &lt;%= submit_tag "Search", :name =&gt; nil %&gt; 
    &lt;%= link_to_function "Clear", "$('search_field').clear()" %&gt;
  &lt;% end %&gt; 
  </code></pre>
  
  <h1>_search_results (partial):</h1>
  
  <pre><code>&lt;div class="Results list"&gt;
  
    &lt;table class="Resultslisting" summary="Result list"&gt;
    &lt;tr class="header"&gt;
    &lt;th&gt;Current Location&lt;/th&gt;
    &lt;th&gt;Date/Time&lt;/th&gt;
    &lt;/tr&gt;
  &lt;% if !@histories.empty? %&gt;
    &lt;% @histories.each do |result| %&gt;
    &lt;tr&gt;
    &lt;td&gt;&lt;%= result.current_location %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= result.updated_at %&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;% end %&gt;
    &lt;/table&gt;
  &lt;% else %&gt;
     &lt;p&gt; The tracking number does not exist!&lt;/p&gt;
  &lt;% end %&gt;
  
  &lt;/div&gt;
  </code></pre>