Reputation: 541
Newbie question! I'm trying to get my head around how I can set up specific Active Record searches which I then call from my controllers. Why is this throwing an undefined method error?
method defined in the Model:
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
Controller
def index
@events = Event.next_seven_days
end
Upvotes: 1
Views: 1908
Reputation: 31726
because you haven't defined the method you're calling as a class method
try
def self.next_seven_days
in the activerecord class instead of what you have
Upvotes: 2