사이트 맵 생성 프로그램을 만들고있는 순간에 & 레일 애플리케이션을 작성하고 있습니다. 모든 것이 잘되고 내 컴퓨터에서는 여전히 문제가 없습니다. 그러나 Heroku에 배포 할 때 문제가 발생합니다. 그것은 단지 하나 개의 자원의 모든 URL을 기록하고 코드는 다음과 같습니다 :Heroku는 배포 후 한 번만 쿼리를 실행합니다.
생성기는 매우 간단합니다 작동
컨트롤러 :
class SitemapController < ApplicationController
layout nil
def index
@solutions = Solution.find(:all, :order => "updated_at DESC")
@base_url = "http://#{request.host_with_port}"
headers['Content-Type'] = 'application/xml'
def index
respond_to do |format|
format.html
format.xml
end
end
end
end
보기 :
<% if @solutions %>
<url>
<loc><%= "#{@base_url}#{solutions_path}" %></loc>
<lastmod><%= @solutions.first.updated_at.to_s(:sitemap) %></lastmod>
<priority>0.6</priority>
</url>
<% @solutions.each do |solution| %>
<url>
<loc><%= "#{@base_url}#{url_for(solution)}" %></loc>
<lastmod><%= solution.updated_at.to_s(:sitemap) %></lastmod>
<priority>0.5</priority>
</url>
<% end %>
나 '로 이미 로컬에서는 제대로 작동하지만 Heroku에서는 배포 후 한 번만 예상 결과가 표시되지만 다른 모든 경우에는 솔루션을 선택하지 않아도 링크가 표시되지 않습니다.
여기 로그입니다
2012-01-05T16:32:34+00:00 app[web.1]: Started GET "/sitemap.xml" for 194.44.214.138 at 2012-01-05 16:32:34 +0000
2012-01-05T16:32:34+00:00 app[web.1]:
2012-01-05T16:32:34+00:00 app[web.1]: Processing by SitemapController#index as XML
2012-01-05T16:32:34+00:00 app[web.1]: Solution Load (5.1ms) SELECT "solutions".* FROM "solutions" ORDER BY updated_at DESC
2012-01-05T16:32:34+00:00 app[web.1]: (1.4ms) SHOW search_path
2012-01-05T16:32:34+00:00 app[web.1]: Rendered sitemap/index.xml.erb (19.4ms)
2012-01-05T16:32:34+00:00 app[web.1]: Completed 200 OK in 92ms (Views: 70.4ms | ActiveRecord: 21.3ms)
2012-01-05T16:32:34+00:00 app[web.1]: cache: [GET /sitemap.xml] miss
2012-01-05T16:32:40+00:00 app[web.1]:
2012-01-05T16:32:40+00:00 app[web.1]:
2012-01-05T16:32:40+00:00 app[web.1]: Started GET "/sitemap.xml" for 194.44.214.138 at 2012-01-05 16:32:40 +0000
2012-01-05T16:32:40+00:00 app[web.1]: Processing by SitemapController#index as XML
2012-01-05T16:32:40+00:00 app[web.1]: Rendered sitemap/index.xml.erb (0.0ms)
2012-01-05T16:32:40+00:00 app[web.1]: Completed 200 OK in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms)
2012-01-05T16:32:40+00:00 app[web.1]: cache: [GET /sitemap.xml] miss
2012-01-05T16:32:40+00:00 heroku[router]: GET www.my.url/sitemap.xml dyno=web.1 queue=0 wait=0ms service=9ms status=200 bytes=299
2012-01-05T16:32:43+00:00 app[web.1]:
2012-01-05T16:32:43+00:00 app[web.1]:
2012-01-05T16:32:43+00:00 app[web.1]: Started GET "/sitemap.xml" for 194.44.214.138 at 2012-01-05 16:32:43 +0000
2012-01-05T16:32:43+00:00 app[web.1]: Processing by SitemapController#index as XML
2012-01-05T16:32:43+00:00 app[web.1]: Rendered sitemap/index.xml.erb (0.0ms)
2012-01-05T16:32:43+00:00 app[web.1]: Completed 200 OK in 0ms (Views: 0.3ms | ActiveRecord: 0.0ms)
2012-01-05T16:32:43+00:00 app[web.1]: cache: [GET /sitemap.xml] miss
2012-01-05T16:32:43+00:00 heroku[router]: GET www.my.url/sitemap.xml dyno=web.1 queue=0 wait=0ms service=7ms status=200 bytes=299
2012-01-05T16:32:44+00:00 app[web.1]:
2012-01-05T16:32:44+00:00 app[web.1]:
2012-01-05T16:32:44+00:00 app[web.1]: Started GET "/sitemap.xml" for 194.44.214.138 at 2012-01-05 16:32:44 +0000
2012-01-05T16:32:44+00:00 app[web.1]: Processing by SitemapController#index as XML
2012-01-05T16:32:44+00:00 app[web.1]: Rendered sitemap/index.xml.erb (0.0ms)
2012-01-05T16:32:44+00:00 app[web.1]: Completed 200 OK in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms)
2012-01-05T16:32:44+00:00 app[web.1]: cache: [GET /sitemap.xml] miss
2012-01-05T16:32:44+00:00 heroku[router]: GET www.my.url/sitemap.xml dyno=web.1 queue=0 wait=0ms service=30ms status=200 bytes=299
그래서 당신은 Solution Load
만 첫 번째 요청에 발행하고 다른 것들 중에 건너 볼 수 있습니다. 무엇이 문제인지 아십니까?
그런데 이전 버전을 사용해 보지 않았지만 Google 웹 마스터 도구에서 모든 것이 정상적으로 보였습니다. 이것은 내가 만든 서식 변경으로 인해 발생할 수 있습니까? 나는
설정/초기화/time_formats.rb
Time::DATE_FORMATS[:sitemap] = "%Y-%m-%d"
과
.to_s(:sitemap)
방법은 updated_at
호출 컨트롤러에 다음 줄을 추가했습니다.
나는 모든 종류의 회신이나 힌트에 대해 매우 감사 할 것입니다.
컨트롤러에서 before_filters가 무엇인지, 메서드가 어떻게 보이는지 등 자세한 정보를 제공 할 수 있습니까? – andrewpthorp
@andrewpthorp 편집 설명, 이제 전체 컨트롤러가 표시됩니다. – Uko