希望根据Rails 2.0.2中的条件限制查找。
查找声明:
@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ])
需要添加限制查找的条件
:conditions=>["archived = '0'"]
虽然这不起作用
@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["archived = '0'"])
任何人都知道语法应该是什么?
答案 0 :(得分:0)
如果你传递一个数组条件,我认为它需要是一个参数化的条件。尝试以下两种情况之一:
@employees = Employee.find_by_contents(params[:keywords].to_s,
:include => [ :categories, :revisions, :approvals,
:archives, :related_documents ],
:conditions=> "archived = '0'")
或
@employees = Employee.find_by_contents(params[:keywords].to_s,
:include => [ :categories, :revisions, :approvals,
:archives, :related_documents ],
:conditions=>["archived = ?",'0'])
答案 1 :(得分:0)
首先,你有什么错误?
试试这个
@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["employees.archived = ?", false])
答案 2 :(得分:0)
有很多时间为ferret find_by添加一个条件,所以我添加了一个post命令来过滤它是否已存档。如果你想到更好的方式,请告诉我。感谢。
@employees = Employee.find_by_contents(params[:keywords].to_s,
:include => [ :categories, :revisions, :approvals,
:archives, :related_documents ])
@employees = @employees.find_all {|p| !p.archived}