Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rails,防止Model.scoped、find(:all)和relation#all的弃用警告?_Ruby_Rspec_Deprecated - Fatal编程技术网

Ruby Rails,防止Model.scoped、find(:all)和relation#all的弃用警告?

Ruby Rails,防止Model.scoped、find(:all)和relation#all的弃用警告?,ruby,rspec,deprecated,Ruby,Rspec,Deprecated,我有通过的测试,但显示 $ rspec spec/event_calendar_spec.rb ......DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. (called from events_for_date_range at /home/durrantm/Dropbox/96_2013/work/code/ruby/event_calendar/lib/event_calenda

我有通过的测试,但显示

$ rspec spec/event_calendar_spec.rb 
......DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. (called from events_for_date_range at /home/durrantm/Dropbox/96_2013/work/code/ruby/event_calendar/lib/event_calendar.rb:52)
DEPRECATION WARNING: Calling #find(:all) is deprecated. Please call #all directly instead. You have also used finder options. These are also deprecated. Please build a scope instead of using finder options. (called from events_for_date_range at /home/durrantm/Dropbox/96_2013/work/code/ruby/event_calendar/lib/event_calendar.rb:52)
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from events_for_date_range at /home/durrantm/Dropbox/96_2013/work/code/ruby/event_calendar/lib/event_calendar.rb:52)
模型是:

 50     # Get the events overlapping the given start and end dates
 51     def events_for_date_range(start_d, end_d, find_options = {})
 52       self.scoped(find_options).find(
 53         :all,
 54         :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)", start_d.to_time.utc, end_d.to_time.utc ],
 55         :order => "#{self.quoted_table_name}.#{self.start_at_field} ASC"
 56       )
 57     end
50#获取与给定开始和结束日期重叠的事件
51定义日期范围内的事件(开始、结束、查找选项={})
52自作用域(查找选项)。查找(
53:全部,

54:conditions=>[”(?
all
是隐含的,在使用作用域时不需要它

 50     # Get the events overlapping the given start and end dates
 51     def events_for_date_range(start_d, end_d, find_options = {})
 52       self.where(find_options,
 53         :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)", start_d.to_time.utc, end_d.to_time.utc ],
 54         :order => "#{self.quoted_table_name}.#{self.start_at_field} ASC"
 55       ) 
 56     end
如果您在rails 4中使用
all
作为强制快速加载的方法,那么现在应该使用

 50     # Get the events overlapping the given start and end dates
 51     def events_for_date_range(start_d, end_d, find_options = {})
 52       self.where(find_options,
 53         :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)", start_d.to_time.utc, end_d.to_time.utc ],
 54         :order => "#{self.quoted_table_name}.#{self.start_at_field} ASC"
 55       ).load
 56     end
50#获取与给定开始和结束日期重叠的事件
51定义日期范围内的事件(开始、结束、查找选项={})
52.在何处(查找选项,

53:conditions=>[”(?您是否尝试过我使用
load
all
的答案?
 50     # Get the events overlapping the given start and end dates
 51     def events_for_date_range(start_d, end_d, find_options = {})
 52       self.where(find_options,
 53         :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)", start_d.to_time.utc, end_d.to_time.utc ],
 54         :order => "#{self.quoted_table_name}.#{self.start_at_field} ASC"
 55       ) 
 56     end
 50     # Get the events overlapping the given start and end dates
 51     def events_for_date_range(start_d, end_d, find_options = {})
 52       self.unscoped.where(find_options,
 53         :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)", start_d.to_time.utc, end_d.to_time.utc ],
 54         :order => "#{self.quoted_table_name}.#{self.start_at_field} ASC"
 55       ) 
 56     end
 50     # Get the events overlapping the given start and end dates
 51     def events_for_date_range(start_d, end_d, find_options = {})
 52       self.where(find_options,
 53         :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)", start_d.to_time.utc, end_d.to_time.utc ],
 54         :order => "#{self.quoted_table_name}.#{self.start_at_field} ASC"
 55       ).load
 56     end