Reputation: 267
How would i write
(A OR B) AND B
in a controller?
Now i have this (a OR b)
@articles = Article.where ("author = ? OR title = ?"), params[:author],params[:title])
Or is there a more elegant way to achieve the same result? (scopes??)
Upvotes: 2
Views: 564
Reputation: 906
This is precisely the sort of problem that I wrote MetaWhere (http://metautonomo.us/projects/metawhere) to solve.
With MetaWhere, that query would be writen something like this:
@articles = Article.where(:author.eq % params[:author] | :title.eq % params[:title])
or this:
@articles = Article.where({:author => params[:author]} | {:title => params[:title]})
Upvotes: 3