我正在编写一个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