我正在編寫一個Rails應用程序&,此刻我正在生成站點地圖生成器。一切都很好,在我的電腦上仍然很好。但是當我將它部署到Heroku時,我遇到了一個問題。Heroku在部署後只運行一次查詢
發電機的工作原理很簡單:它只是寫一個資源的所有URL和代碼如下所示:
控制器:
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
僅在第一請求發出並在其他的跳過。 你有什麼想法是什麼問題?
順便說一句,我沒有嘗試過以前的版本,但從谷歌網站管理員工具,似乎一切都很好。這可能是由我所做的格式更改造成的嗎?我已經添加了下一行
配置/初始化/ time_formats.rb
Time::DATE_FORMATS[:sitemap] = "%Y-%m-%d"
,並在控制器
.to_s(:sitemap)
方法調用的updated_at
。
我會非常感謝任何回覆或提示。
你能提供更多的信息從控制器,什麼是before_filters存在,什麼樣的方法,等等? – andrewpthorp 2012-01-05 17:25:24
@andrewpthorp編輯描述,現在完整控制器顯示 – Uko 2012-01-05 17:36:38