Sitemap生成器无法找到表 - StatementInvalid

时间:2014-08-22 08:05:22

标签: ruby-on-rails ruby ruby-on-rails-3 sitemap-generator-gem

我正在使用站点地图生成器来生成我的站点地图。 我已经在本地测试了所有代码,并且我已准备好在在线网络服务器上进行尝试,当我尝试刷新Sitemap bundle exec rake sitemap:refresh时发生以下情况:

ActiveRecord::StatementInvalid: Could not find table 'settings'

在sitemap.rb中执行的代码:

SitemapGenerator::Sitemap.create do
      settings = Settings.first
      languages = []
      languages << "en" if settings.lang_en
      languages << "fr" if settings.lang_fr
      languages << "nl" if settings.lang_nl
      languages << "de" if settings.lang_de
end

网络服务器控制台中相同代码的结果:

[1] pry(main)> settings = Settings.first
  Settings Load (2.0ms)  SELECT "settings".* FROM "settings" LIMIT 1
  Settings::Translation Load (2.0ms)  SELECT "setting_translations".* FROM "setting_translations" WHERE "setting_translations"."setting_id" = 1

  #Output here

[2] pry(main)> languages = []
=> []
[3] pry(main)> languages << "en" if settings.lang_en
=> nil
[4] pry(main)> languages << "fr" if settings.lang_fr
=> ["fr"]
[5] pry(main)> languages << "nl" if settings.lang_nl
=> ["fr", "nl"]
[6] pry(main)> languages << "de" if settings.lang_de
=> nil
[7] pry(main)> languages
=> ["fr", "nl"]

完整错误:

rake aborted!
ActiveRecord::StatementInvalid: Could not find table 'settings'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/connection_adapters/sqlite_adapter.rb:472:in `table_structure'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/model_schema.rb:229:in `yield'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/model_schema.rb:229:in `default'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/model_schema.rb:229:in `columns'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/model_schema.rb:238:in `columns_hash'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/locking/optimistic.rb:131:in `locking_enabled?'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/relation.rb:170:in `exec_queries'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/relation.rb:160:in `block in to_a'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/explain.rb:34:in `logging_query_plan'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/relation.rb:159:in `to_a'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/relation/finder_methods.rb:381:in `find_first'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/relation/finder_methods.rb:122:in `first'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/querying.rb:5:in `first'
/home/<customer_here>/apps/default/releases/324/config/sitemap.rb:8:in `block in run'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator/interpreter.rb:59:in `instance_eval'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator/interpreter.rb:59:in `eval'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator/link_set.rb:40:in `create'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator.rb:42:in `method_missing'
/home/<customer_here>/apps/default/releases/324/config/sitemap.rb:5:in `run'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator/interpreter.rb:76:in `instance_eval'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator/interpreter.rb:76:in `run'
/home/<customer_here>/apps/default/releases/324/vendor/bundle/ruby/1.9.1/gems/sitemap_generator-5.0.5/lib/sitemap_generator/tasks.rb:51:in `block (2 levels) in <top (required)>'
Tasks: TOP => sitemap:refresh => sitemap:create
(See full trace by running task with --trace)

使用的宝石:https://github.com/kjvarga/sitemap_generator

操作系统:Mac OS X 10.9.4

Rails版本:Rails 3.2.18

Ruby版本:ruby 1.9.3p484

亲切的问候。

EDIT1:尝试更改变量设置 - 同样的错误

  langu_settings = Settings.first
  languages = []
  languages << "en" if langu_settings.lang_en
  languages << "fr" if langu_settings.lang_fr
  languages << "nl" if langu_settings.lang_nl
  languages << "de" if langu_settings.lang_de

1 个答案:

答案 0 :(得分:2)

尝试像bundle exec rake sitemap:refresh RAILS_ENV=production一样运行它。