开发者

Rails sitemap generator, undefined method post_path?

I am using the following gem:

https://github.com/kjvarga/sitemap_generator

I have a posts model and have used post_path(post) in other parts of the application as it is based on Enki.

However in the sitemap file:

开发者_如何学编程
Post.all.each do |post|
    sitemap.add post_path(post), :lastmod => post.updated_at
  end

This returns the error when running the rake task rake sitemap:refresh:

rake aborted!
undefined method `post_path' for #<SitemapGenerator::Interpreter:0x279efd0>

And:

Post.all.each do |post|
  sitemap.add posts_path(post), :lastmod => post.updated_at
end

Returns no errors. Can anyone shed any light on this or do I need to provide more of the code?


sitemap_generator actually includes all the helper methods in the create block, so you should be able to access posts_path.

I had a similar problem, and my answer also made me feel stupid. I was storing sitemap.rb in config/initializers, when it should be stored in the config/ directory. That meant it was running on startup and failing because the url helpers weren't properly loaded (and, incidentally, when I called rake sitemap:refresh, the sitemap was being generated twice - once in the initializer and again as the rake task!)


I feel a bit stupid on this one, it was simply because post_path was a helper and not accessible, so I simply had to move it into the method directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜