나는 Postgres 데이터베이스에 대해 실행되는 Roku 3 앱을 Heroku에서 호스팅하고 있습니다. RSS 피드를 생성해야하는 컨트롤러 동작이 있지만 응용 프로그램이 다시 시작될 때까지 업데이트되지 않습니다. (Heroku에 대한 새 릴리스를 수행하거나 사이트가 잠시 동안 비활성 상태가되어 dyno 회전하고 다시 백업). 새 항목을 제외하는 '오래된'데이터가 반환됩니다.Rails가 다시 시작될 때 Date.current의 범위 만 업데이트됩니다.
는 범위는 내 모델에 행 사이의 비교를 기반으로,과 같이 정의된다는 date
및 Date.current
전화 : 당신이 할 수
class PetitionsController < ActionController::Base
before_filter :find_diary
def rss
current_petitions.each do |petition|
puts petition.date
end
end
protected
def find_diary
@diary = Diary.find(params[:id])
end
def current_petitions
@diary.petitions.published.current.limit(25)
end
end
:
class Petition < ActiveRecord::Base
scope :current, where(["petitions.date <= ?", Date.current]).order("petitions.date DESC")
scope :published, { :conditions => { :published => true } }
end
컨트롤러 액션이 같다 보시다시피 오늘 또는 그 이전의 date
으로 모든 청원서를 반환해야합니다. 그것은 Heroku 콘솔에서 잘 작동합니다. Diary.find(15).petitions.published.current.limit(25).first
은 항상 오늘 나를 위해 하나를줍니다. 로그에서 피드가 요청 될 때마다 current_petitions
함수가 호출되는 것을 볼 수 있습니다. 그러나 24 시간 동안 사이트를 계속 운영한다면 어제까지 계속해서 탄원서를 보여줄뿐입니다. 디버그 코드를 추가하기 위해 릴리스를 수행하면 갑자기 다시 작동하기 시작합니다.
얼마나 쉽게 알 수 있습니다! – andygeers