Rails sitemap_generator Uninitialized Constant?
Asked Answered
M

2

5

I'm trying to use the Rails site map_generator gem to generate site maps for a 8,000,00 page site. The gem can be found here: https://github.com/kjvarga/sitemap_generator

Here is my code in sitemap.rb:

require 'rubygems'
require 'sitemap_generator'

# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://www.mysite.com"

SitemapGenerator::Sitemap.create do
  add '/content.aspx?page=privacypolicy'
  Product.find_each do |product|
    add product_path(ppid), :lastmod => content.updated_at
  end
end

However, when I run

>> ruby sitemap.rb  

I get an error that says:

sitemap.rb:9:in `block in ': uninitialized constant SitemapGenerator::Interpreter::Product (NameError)

However "Product" is the correct name of my model. Why is this happening?

I'm running Rails 3.1.2 and Ruby 1.9.

Mayflower answered 31/5, 2012 at 0:36 Comment(0)
B
16

I'm the author of the gem. Better to open an issue on the GitHub page in future. SitemapGenerator does work in Rails 3 and Ruby 1.9.*. If you are running Rails, you don't need these lines:

require 'rubygems'
require 'sitemap_generator'

Also you generate your sitemaps by running Rake:

rake sitemap:refresh:no_ping

What is happening in your case is that because you're not running through Rake, the script does not know about the Product class, since your Rails environment hasn't been loaded.

Benign answered 2/5, 2013 at 22:41 Comment(1)
Kindly put this thing at top along with ruby command. I guess no one is generating it via ruby. Most are rails users and they dont want to read till end of doc.Whelp
M
0

Well, I wasn't able to get this gem working. My guess is that it doesn't work on Rails 3.1.2 or with Ruby 1.9. However, I was able to get another gem (big_sitemap) to work. Here is the link to it.

https://github.com/alexrabarts/big_sitemap

Mayflower answered 31/5, 2012 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.