开发者

ActiveRecord find() with negated condition

开发者 https://www.devze.com 2023-02-07 19:23 出处:网络
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\' })

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

精彩评论

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