合并 conditions

1
2
3
4
5
6
7
8
9
10
@conditions = [] 
@con1 = params[:category] ? (@conditions << "company_categories.cat_name = '#{params[:category]}'") : nil 
@con2 = params[:alpha] ? (@conditions << "companies.name LIKE '#{params[:alpha]}%'") : nil 

# count the number of records returned with includes and conditions set 
@company_count = Company.count(:include => includes, :conditions => @conditions.join(" and ")) 

# Finally, our find 
@companies = Company.paginate :page => params[:page], :per_page => 10, :order => 'name', :include => includes, :conditions => @conditions.join(" and ") 

@conditions = []
@conditions << xx if xx
:conditions => @conditions.join(" and ")

    Posted by devon At October 25, 2008 19:19

请登录以发表评论。