hiii 레일스의 새로운 소식입니다. 이벤트라는 모델이 있으며 오늘의 이벤트, 지난 이벤트 및 향후 이벤트가 있습니다. 인덱스 페이지에서 내 이벤트의 수를 표시하고 있습니다. 아약스를 사용하여 카운트를 업데이트하여 내 페이지가 깜박 거리지 않도록하고 싶습니다.Ajax를 사용하여 이벤트를 업데이트하는 방법
컨트롤러에 대한 내 코드는 다음과 같습니다
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
및 뷰에 대한 코드는 다음과 같습니다,
여기%li
- if params[:controller] == "brands"
%a.tt-top-center{:title => "Total approvals pending"}#{Brand.all.size}
%span Past Brands
- elsif params[:controller] == "events"
%a.tt-top-center{:title => "upcoming Events", :href => events_path(:view => "upcoming") }#{Event.count_upcoming}
%span Upcoming Events
%li
- if params[:controller] == "brands"
%a.tt-top-center{:title => "Total approvals pending"}#{Brand.all.size}
%span New Brand
- elsif params[:controller] == "events"
%a.blue.tt-top-center{:title => "past Events", :href => events_path(:view => "past") }#{Event.count_past}
%span Past Events Blockquote
내 카운트 기능은 현재, 과거와 앞으로의 사건의 수를 표시 할 수 있지만, 나는 ajax를 사용하여 업데이트하고 싶다. 전문가의 도움을 받으십시오
안녕하세요, 저는 3 일 동안이 방법을 시도하고 있습니다. 정확한 방법을 모르는 경우, 설명적인 방식으로 알려주십시오. 나는 함수 remove_im_address (id), container.html (data)가 무엇인지 알지 못한다. – DSH
hii !! 나는 몇 달 전에이 질문을 던졌지 만이를 해결했지만 여기에 그것을 잊어 버렸습니다. 도와 주셔서 감사합니다.하지만 다른 방식으로 해결했습니다. 내 대답을 찾으십시오. – DSH