我的事件模型代码是这样的:
def current_date
Date.today
end
def self.count_past(current_date = Date.today)
Event.count :all, :conditions => ['start_date < ?', current_date], :order => 'start_date'
end
def self.count_upcoming(current_date = Date.today)
Event.count :all, :conditions => ['start_date > ?', current_date], :order => 'start_date'
#this statment is equivalent to
#select * from events where start_date > current_date order by start_date
end
def self.count_today(current_date = Date.today)
Event.count :all, :conditions => ['start_date = ?', current_date], :order => 'start_date'
end
我的代码view(index file)
是这样的:
%li
%a.tt-top-center{:title => "Total Events", :href => events_path}#{Event.all.size}
%span Total events
%li
%a.blue.tt-top-center{:title => "Today's Events", :href => events_path(:view => "today")}#{Event.count_today}
%span Today's Events
%li
%a.green.tt-top-center{:title => "Past Events", :href => events_path(:view => "past")}#{Event.count_past}
%span Past Events
%li
%a.tt-top-center{:title => "Upcoming Events", :href => events_path(:view => "upcoming")}#{Event.count_upcoming}
%span Upcoming Events
我的controllers
代码是这样的:def index
case params[:view]
when 'past'
@events = Event.find (:all, :conditions => ['start_date < ?', current_date], :order => 'start_date')
when 'today'
@events = Event.find (:all, :conditions => ['(start_date = current_date)'], :order => 'start_date ')
when 'upcoming'
@events = Event.find(:all, :conditions => ['start_date > ?', current_date], :order => 'start_date')
else
@events = Event.all
end
end
请告诉我ajax
当我单击相应的链接等时如何使用today's events
,total events
以及如何使用更新事件计数jquery