1

新手问题!我试图弄清楚如何设置特定的 Active Record 搜索,然后从我的控制器调用这些搜索。为什么这会引发未定义的方法错误?

模型中定义的方法:

class Event < ActiveRecord::Base

    attr_accessible :category, :date_end, :date_start, :description, :time_start, :title, :venue, :image


    def next_seven_days
        t = Time.now
        Event.where("date_end BETWEEN ? AND ?", t, t+7.days).order("date_end ASC")
    end
end

控制器

def index
    @events = Event.next_seven_days     
end
4

1 回答 1

2

因为您还没有将要调用的方法定义为类方法

尝试

 def self.next_seven_days

在 activerecord 类中,而不是你所拥有的

于 2013-05-25T04:31:48.863 回答