Topic: conditionals ?

So I am digging through the checkbox trying to get it all working in the controller, and now told that that find logic goes in the model..

But a few times I have seen things like :conditional => conditional, and from this post http://railsforum.com/viewtopic.php?id=357&p=2
  conditions << "make = #{sanitize(make)}" unless make.blank?


is this the route to go to get the checkbox to send the filter system I am after ? If so do you have some small doc for conditional or condition?

Re: conditionals ?

Yeah, I usually move complex searches into the model. Something like this:

# in your view
<%= start_form_tag :action => 'search' %>
  <%= text_field_tag :keyword %>
  <%= check_box_tag 'filters[city]' %> City
  <%= check_box_tag 'filters[county]' %> County
  <%= check_box_tag 'filters[state]' %> State
  <%= submit_tag 'Search' %>
<%= end_form_tag %>

# in your controller
def search
  @models = Model.find_filtered(params[:keyword], params[:filters]) # replace Model with your own model.
end

# in your model
def self.find_filtered(keyword, filters = {})
  conditions = []
  column_names.each do |column|
    conditions << "#{column} = #{sanitize(keyword)}" unless filters[column].blank?
  end
  find(:all, :conditions => conditions.join(' or '))
end


Does that make sense?

Railscasts - Free Ruby on Rails Screencasts

Re: conditionals ?

HELL ya!.. finally it's starting to make sense.. MAny super thank yous.. I am reading now..