0
내 이벤트 모델 코드 수를 갱신하는 방법이 같다 :아약스
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
코드는 다음과 같다 : 데프 인덱스
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
클릭하고 난 당신이 AJAX 호출을위한 :remote => true
를 사용할 필요가 jquery
컨트롤러를 다음과 같이 업데이트했습니다. respond_to do | format | format.html {redirect_to @event} # new.html.erb format.js {render : partial => 'show', : locals => {: event => @event}} 끝 부분도 만들었습니다. 그것을 컨트롤러에서 보여주고 불러 냈다. 그러나 템플릿 누락과 같은 오류가 발생합니다. Plz 내가 무엇을 해야할지 말해주십시오 –
@SnehaKachroo 질문에 컨트롤러 및 기타 (관련) 코드를 업데이트 할 수 있습니까? 또한 정확한 오류 메시지는 무엇입니까? –
오류가 발생하지 않고 항목이 아약스에 의해 성공적으로 삭제되지만 카운트가 업데이트되지 않습니다. 내 페이지를 수동으로 새로 고친 후에야 정확한 숫자가 표시됩니다. 아약스로 업데이트하는 법을 가르쳐주세요 –