【问题标题】:undefined local variable or method `config' for main:Objectmain:Object 的未定义局部变量或方法“config”
【发布时间】:2013-12-03 15:10:21
【问题描述】:

我试图将 rails 2.3 应用程序迁移到 rails 3.13。随后,我将我的 gem 配置转移到 Gemfile 并安装了 Bundle。我已更新 routes.rb 以符合新格式。

但我无法启动我的应用程序。现在卡了一段时间。想不通到底在哪里。错误来自。

这是我从 Phushion Passenger 的回溯。

0   rails_apps/gsnapweb/vendor/plugins/delayed_job/rails/init.rb    3   in `'
1   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.13/lib/active_support/dependencies.rb   251 in `require'
2   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.13/lib/active_support/dependencies.rb   251 in `block in require'
3   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.13/lib/active_support/dependencies.rb   236 in `load_dependency'
4   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.13/lib/active_support/dependencies.rb   251 in `require'
5   rails_apps/gsnapweb/vendor/plugins/delayed_job/init.rb  1   in `block in '
6   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/plugin.rb   82  in `eval'
7   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/plugin.rb   82  in `block in '
8   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/initializable.rb    30  in `instance_exec'
9   rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/initializable.rb    30  in `run'
10  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/initializable.rb    55  in `block in run_initializers'
11  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/initializable.rb    54  in `each'
12  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/initializable.rb    54  in `run_initializers'
13  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/application.rb  136 in `initialize!'
14  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/railties-3.2.13/lib/rails/railtie/configurable.rb 30  in `method_missing'
15  rails_apps/gsnapweb/config/environment.rb   5   in `'
16  config.ru   3   in `require'
17  config.ru   3   in `block in'
18  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/rack-1.4.5/lib/rack/builder.rb    51  in `instance_eval'
19  rails_apps/gsnapweb/vendor/bundle/ruby/1.9.3/gems/rack-1.4.5/lib/rack/builder.rb    51  in `initialize'
20  config.ru   1   in `new'
21  config.ru   1   in `'

这是我的 Gemfile。

1 source 'https://rubygems.org'
2
3 gem 'rails', '3.2.13'
4
5 # Bundle edge Rails instead:
6 # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
8 gem 'mysql2'
9
10
11 # Gems used only for assets and not required
12 # in production environments by default.
13 group :assets do
14   gem 'sass-rails',   '~> 3.2.3'
15   gem 'coffee-rails', '~> 3.2.1'
16
17   # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18   # gem 'therubyracer', :platforms => :ruby
19
20   gem 'uglifier', '>= 1.0.3'
21 end
22
23 gem 'will_paginate', '>=3.0.pre'
24 gem 'jquery-rails'
25 gem 'rack'
26 gem 'delayed_job_active_record'
27
28 # To use ActiveModel has_secure_password
29 # gem 'bcrypt-ruby', '~> 3.0.0'
30
31 # To use Jbuilder templates for JSON
32 # gem 'jbuilder'
33
34 # Use unicorn as the app server
35 # gem 'unicorn'
36
37 # Deploy with Capistrano
38 # gem 'capistrano'
39
40 # To use debugger
41 # gem 'debugger'

application.rb 文件

require File.expand_path('../boot', __FILE__)
require 'rails/all'

+--  6 lines: if defined?(Bundler)----------------------------------------------------------------------------

module Gsnapweb
class Application < Rails::Application
 config.encoding = "utf-8"

 # Configure sensitive parameters which will be filtered from the log file.
 config.filter_parameters += [:password]

 # Enable escaping HTML in JSON.
 config.active_support.escape_html_entities_in_json = true
      config.active_record.whitelist_attributes = true

 # Enable the asset pipeline
 config.assets.enabled = true

 # Version of your assets, change this if you want to expire all your assets
 config.assets.version = '1.0'

 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
          :address => 'mail.example.net',
          :port    => 26,
          :authentication => 'plain',
          :user_name => 'xxxxxx',
          :password => 'xxxxxx',
 }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_charset = 'utf-8'

【问题讨论】:

  • 你能发布你的 environment.rb 文件吗?

标签: ruby-on-rails ruby-on-rails-3 bundler


【解决方案1】:

您应该从vendor/plugins 中删除delayed_job,因为您将它包含在您的Gemfile 中。

一般来说,从 Rails 2 升级到 3 时,您应该尝试将 vendor/plugins 中的 Rails 插件替换为 Gemfile 中的 gem。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2014-08-07
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    相关资源
    最近更新 更多