2 用一个变量查找条件

发布于 2024-10-01 06:00:19 字数 559 浏览 0 评论 0原文

现在我的 Projects.paginate 中只有一个条件 代码如下,

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

我想在这里添加另一个条件,但事实证明它很困难。我尝试过

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

,但我从 SQL 控制器收到绑定错误。有什么想法吗?我也不能使用 = 符号。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-10-08 06:00:19

您的条件数组中需要有两个绑定变量:

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

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

qt = "%#{query}%"
@projects = Project.paginate(:conditions => 
              ["description LIKE ? OR name LIKE ?", qt, qt], ..)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文