未定义的方法`sass'代表#

时间:2011-10-13 15:10:22

标签: heroku rake ruby-on-rails-3.1 sass

我看了一下,没有发现类似的错误。 我不记得曾修改我的production.rb。好的方面,这是我的application.rb

这是来自Heroku的堆栈跟踪。

$ heroku run rake db:migrate --remote staging --trace

Running rake db:migrate --trace attached to terminal... up, run.2
/app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53:      warning: already initialized constant WFKV_
rake aborted!

undefined method `sass' for #<Rails::Application::Configuration:0x000000047c6fb0>
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configuration.rb:78:in `method_missing'
/app/config/application.rb:63:in `<class:Application>'
/app/config/application.rb:18:in `<module:Instantice>'
/app/config/application.rb:17:in `<top (required)>'
/app/Rakefile:5:in `require'
/app/Rakefile:5:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:78:in `block in load_rakefile'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:61:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'

我最初认为application.rb中的这一行可能导致这种情况(尽管以前从未有过)。

config.sass.preferred_syntax = :sass

删除它虽然没有结果。

3 个答案:

答案 0 :(得分:34)

我有同样的错误......

我只需要将gem 'sass-rails'移出资产组

<强>物

#Gemfile
group :assets do
   gem 'sass-rails'  # Was giving me errors here.
   ...
end

<强>是

#Gemfile
gem 'sass-rails'    # No more errors
group :assets do
   ...
end

答案 1 :(得分:5)

我昨天花了整整一天对此进行排查并设法修复它。 我确实删除了config.sass.preferred_syntax行,但这不是唯一的问题。

最重要的是,我错过了对Sprockets来说似乎是一个至关重要的需求声明。 由于我正在使用RSpec,我评论过将application.rb文件中常用的require "rails/all"行拆分为:

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
# require "rails/test_unit/railtie"

当我从Rails 3.x升级到3.1.x时,我只能猜测这是一种疏忽。正确的语句应该包括Sprockets,如下所示:

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
# require "rails/test_unit/railtie"
require "sprockets/railtie"

我还删除了一些我收集过Chris Eppstein Gist on using Compass with 3.1的Compass设置。这是一个绝望的举动,但目前我没有看到任何缺点。

请记住,我不知道自己在做什么。拿一点盐,我只是解释我的“调试”过程。

答案 2 :(得分:0)

如果您还从rails 3.0项目升级,我找到了解决此问题的更好方法: 只需从

更改config / application.rb中的行
Bundler.require(:default, Rails.env) if defined?(Bundler)

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end