Rails Render Actions and Creating a Search Method

One good example of the use of rendering actions in rails is searching. From the Cheatsheet, you might remember that:

Render Action

render :action => 'some_action'   # the default. Does not need to be specified
                                   # in a controller method called "some_action"
render :action => 'another_action', :layout => false
render :action => 'some_action', :layout => 'another_layout'

Using this knowledge, we can do searches in rails like this:

class TemperatureController < ApplicationController
 
   def temp_search_results
    @temperature = Temperature.find(params[:id])
  end
 
  def search 
    @temperature = Temperature.find(:all,
                                :conditions => 
                                    ["name like ?", "%#{params[:cat]}%"])
    if @temperature
      render :action => 'temp_search_results'
    else    
      flash['notice'] = 'No Temperature found.'
      render :action => 'temp_search_form'
    end
  end
 
   def temp_search_form
    end

end

Given that, we know that we'll need to create a view temp_search_results.rhtml in the tempatures views directory. You could also sanitize your results to get rid of characters you know wouldn't be correct. Share your ideas.