2015-07-20 61 views
1

此作品,未经。或者(),但休息时,我将其添加:ActiveRecord的未定义的方法或

<% @expired = Report.where('EXPIRED < ?', Date.new(2014,12,31)).or(Report.where(EXPIRED: nil)).where(:MAJOR => 1).where.not(:TRIBE => 1).where(:PERMIT_TYPE => 'GENERAL') %> 

,给我这个错误:

undefined method `or' for #<Report::ActiveRecord_Relation:0x953e020> 

而且,这样做给了我一个语法错误:

Report.where('EXPIRED < ?', Date.new(2014,12,31) OR (EXPIRED: nil)) 

如何使这个OR工作?

的Rails 4.2.1

+0

是'。或()'活跃在Rails 3的?你从哪里得到这个方法? – onebree

+0

@HunterStevens可能是'or'将随Rails 5一起发布的。它目前在主分支中可用。 –

回答

0

试试这个

Report.where("EXPIRED is null or EXPIRED < ?", Date.new(2014,12,31)) 

和更大的查询做

Report.where("EXPIRED is null or EXPIRED < ?", Date.new(2014,12,31)).where(MAJOR: 1, PERMIT_TYPE: "GENERAL").where.not(TRIBE: 1) 
相关问题