Hard-Boiled Wonderland
Hard-Boiled Wonderland

Reputation: 1399

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?

Upvotes: 1

Views: 2033

Answers (2)

Rob d&#39;Apice
Rob d&#39;Apice

Reputation: 2416

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!)

Upvotes: 3

Hard-Boiled Wonderland
Hard-Boiled Wonderland

Reputation: 1399

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.

Upvotes: 0

Related Questions