Rails sitemap_generator 未初始化的常量? [英] Rails sitemap_generator Uninitialized Constant?

查看:48
本文介绍了Rails sitemap_generator 未初始化的常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Rails 站点 map_generator gem 为一个 8,000,00 页的站点生成站点地图.gem 可以在这里找到:https://github.com/kjvarga/sitemap_generator

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

这是我在 sitemap.rb 中的代码:

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

但是,当我运行时

>> ruby sitemap.rb  

我收到一条错误消息:

sitemap.rb:9:in `block in ': 未初始化的常量SitemapGenerator::Interpreter::Product (NameError)

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?

我正在运行 Rails 3.1.2 和 Ruby 1.9.

I'm running Rails 3.1.2 and Ruby 1.9.

推荐答案

我是 gem 的作者.以后最好在 GitHub 页面上打开一个问题.SitemapGenerator 可以在 Rails 3 和 Ruby 1.9.* 中工作.如果您正在运行 Rails,则不需要这些行:

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'

您还可以通过运行 Rake 来生成站点地图:

Also you generate your sitemaps by running Rake:

rake sitemap:refresh:no_ping

在您的情况下发生的情况是,因为您没有通过 Rake 运行,脚本不知道 Product 类,因为您的 Rails 环境尚未加载.

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.

这篇关于Rails sitemap_generator 未初始化的常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆