在Rails应用程序中安装Haml失败

时间:2009-12-17 05:00:14

标签: ruby-on-rails haml

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

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

/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)的行上。使用script/plugin install安装haml插件会产生相同的错误,而环境.rb顶部的require haml也是如此。不确定它是否有所作为,但在vendor/rails中冻结了

这对我来说非常困惑,如果你能解决这个问题,请提供帮助。

1 个答案:

答案 0 :(得分:2)

如果在初始化程序块之后移动Haml::Template配置,它是否有效?可能是Rails在初始化程序运行之前没有加载插件。