Rails按自定义方法

时间:2017-05-02 19:09:09

标签: ruby-on-rails

我有一个范围来提取

    scope :between, -> (start, endd) {
           where(:start_time => start..endd}
    }

和自定义方法

 def time_of_day 
   Helper.time_of_day(start_time || est_start_time  )
 end 

我希望能够通过自定义方法对结果进行分组

Class.between
Class.between.time_of_start

到目前为止,我已经尝试了

def self.custom_sort
   self.group_by { |a| a.time_of_start }
end 

但是我得到了

  

NoMethodError:未定义的方法`by_time' for Instance :: ActiveRecord_Relation:0x00000005537e60>

我知道我可以做像

这样的事情
Class.between.group_by { |a| a.time_of_start}

但我想定义一个自定义'范围'

2 个答案:

答案 0 :(得分:1)

尝试添加.all,如:

self.all.group_by { |a| a.time_of_start }

Reference

答案 1 :(得分:0)

试试这个:

N

你可以打电话:

decodeURIComponent()
相关问题