运行rake资产时未定义的方法`sub':Windows上的预编译

时间:2013-02-19 15:48:38

标签: ruby-on-rails ruby asset-pipeline rails-activerecord

当我尝试运行rake资产时:预编译我有一个奇怪的问题似乎与我的database.yml有关。但是,直接访问网站工作正常(如果我改变环境以回退资产管道)。

Rails 3.2.12,ruby 1.9.3p385,Windows Server 2008。

我的database.yml文件(删除了主机,用户名和密码):

production:
  adapter: mysql2
  encoding: utf8
  reconnect: true
  database: images
  pool: 5
  username: username
  password: password
  host: host

错误顶部的片段:

D:\inetpub\wwwroot\images>rake assets:precompile
C:/Ruby19/bin/ruby.exe C:/Ruby19/bin/rake assets:precompile:all RAILS_ENV=assets:precompile RAILS_GROUPS=assets
rake aborted!
undefined method `sub' for nil:NilClass
D:/inetpub/wwwroot/images/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in `co
nnection_url_to_hash'
D:/inetpub/wwwroot/images/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:36:in `bl
ock in resolve_string_connection'
D:/inetpub/wwwroot/images/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:35:in `fe
tch'

修改

这是connection_specification.rb的内容,它在这一行上轰炸::database => config.path.sub(%r{^/},""),

       def connection_url_to_hash(url) # :nodoc:
          config = URI.parse url
          adapter = config.scheme
          adapter = "postgresql" if adapter == "postgres"
          spec = { :adapter  => adapter,
                   :username => config.user,
                   :password => config.password,
                   :port     => config.port,
                   :database => config.path.sub(%r{^/},""),
                   :host     => config.host }
          spec.reject!{ |_,value| value.blank? }
          spec.map { |key,value| spec[key] = URI.unescape(value) if value.is_a?(String) }
          if config.query
            options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
            spec.merge!(options)
          end
          spec
        end
      end
    end

1 个答案:

答案 0 :(得分:1)

您的输出会生成: RAILS_ENV =资产:预编译

但是我认为你没有宣布资产环境。

尝试$:. rake assets:precompile RAILS_ENV='production' RAILS_GROUPS='assets'

PS:windows是..让我们说在开发支持时未开发,所以你可能想考虑转换到另一个操作系统。我个人最喜欢的是Debian sqeeze