开发者

2 Find Conditions with one variable

Right now I have only one condition in my Projects.paginate Code is below

   def list
        @projects = Project.paginate(:page => params[:page], :per_page => 100, :order => (sort_column + ' ' + arrow), :conditions => ["description LIKE ?", "%#{query}%"])

I want to put another condition here but its is proving to be difficult. I'v tried

   @projects = Project.paginate(:page => params[:page], :per_page => 100, :order => (sort_column + ' ' + arrow), :conditions => ["description OR name LIKE ?", "%#{query}%"])

but im getting a 开发者_开发问答bind error from the SQL controller. Any ideas? I cant use the = sign either.


You need to have two bind variables in your conditions array:

qt = "%#{query}%"
@projects = Project.paginate(:conditions => 
              ["description LIKE ? OR name LIKE ?", qt, qt], ..)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜