开发者

ActiveRecord find() with negated condition

I can't seem to find a solution to what seems to me like a simple problem.

Sitemap.find(:all, :conditions => { :controller => 'sample', :action => '!index' })

Now obviously the ! in 'index' doesn't belong there, but I put it there to illustrate that I want any result EXCEPT 'index'. I've tried something like the line below but I've gotten server errors whenever I try it.

Sitemap.find(:all, :conditions => { :controller => 'sample',开发者_StackOverflow社区 "action <> 'index'" })


Use the array syntax for this:

Sitemap.all(:conditions => ["controller = ? AND action <> ?", 'sample', 'index']

Hash syntax is only useful if you're checking for equality.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜