1

我有一个小型的 Rails 应用程序,今晚我全神贯注地想要将所有erb转换为haml模板。Haml 文档建议运行haml --rails /path/to/app以将其安装为插件(使用系统上已安装的 gem)。

不幸的是,当我尝试为 rails 启动网络服务器时,我收到以下错误:

/code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant Haml (NameError)
    from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in `const_missing'
    from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in `const_missing'
    from /code/src/myapp/config/environment.rb:15
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:111:in `run'
    from /code/src/myapp/config/environment.rb:5
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
    from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /code/src/myapp/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
    from /code/src/myapp/vendor/rails/railties/lib/commands/server.rb:84
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from ./script/server:3

它在我的环境文件中的一行上呕吐:

# Be sure to restart your server when you modify this file
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Add additional load paths for your own custom dirs
  config.load_paths += %W(
    #{RAILS_ROOT}/lib/
  )

  # Specify gems that this application depends on and have them installed with rake gems:install
  config.gem 'twitter'
  config.gem 'newrelic_rpm'

  Haml::Template.options[:format] = :html5
  Haml::Template.options[:attr_wrapper] = '"'

  config.plugins = [ :all ]
  config.active_record.observers = :user_observer
  config.time_zone = 'UTC' # "rake -D time" for all time zone names.
end

ConsumerConfig = YAML.load(File.read(Rails.root + 'config' + 'twitter-auth.yml'))

错误在于尝试设置一些 Haml 选项 ( Haml::Template.options[:format] = :html5)。安装 haml 插件会产生与environment.rb 顶部script/plugin install相同的错误。require haml不确定它是否有所作为,但 rails冻结在vendor/rails.

这让我很困惑,如果你能解决这个问题,请帮忙。

4

1 回答 1

2

如果您Haml::Template在 Initializer 块之后移动配置,它会起作用吗?可能是 Rails 直到初始化程序运行后才加载插件。

于 2009-12-17T06:41:31.377 回答