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_docum开发者_运维问答ents ], :conditions=>["archived = '0'"])
Anyone know what the syntax should be?
If you pass conditions an array, I think it needs to be for a parameterized condition. Try either/both of the following:
@employees = Employee.find_by_contents(params[:keywords].to_s,
:include => [ :categories, :revisions, :approvals,
:archives, :related_documents ],
:conditions=> "archived = '0'")
or
@employees = Employee.find_by_contents(params[:keywords].to_s,
:include => [ :categories, :revisions, :approvals,
:archives, :related_documents ],
:conditions=>["archived = ?",'0'])
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.
@employees = Employee.find_by_contents(params[:keywords].to_s,
:include => [ :categories, :revisions, :approvals,
:archives, :related_documents ])
@employees = @employees.find_all {|p| !p.archived}
Firstly, what error do you have?
And try this
@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["employees.archived = ?", false])
精彩评论