Rails:有条件的 find_by_contents;请语法帮助
希望根据 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'"])
有人知道语法应该是什么吗?
Looking to limit a find based on conditions in a Rails 2.0.2.
Find statement:
@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ])
Need to add a condition to limit find
:conditions=>["archived = '0'"]
Though this doesn't work
@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["archived = '0'"])
Anyone know what the syntax should be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将条件传递给数组,我认为它需要用于参数化条件。尝试以下任一/两个操作:
或
If you pass conditions an array, I think it needs to be for a parameterized condition. Try either/both of the following:
or
在向 ferret find_by 添加条件方面花了很长时间,因此我添加了一个 post 命令来过滤它是否已存档。如果您还想到更好的方法,请告诉我。谢谢。
Was having quite a time with adding a condition to ferret find_by, so I added a post command to filter if it's archived. If you think of a better way still, let me know. Thanks.
首先,你有什么错误?
并尝试这个
Firstly, what error do you have?
And try this