Rails 3.2 - 无法预编译资产

时间:2013-09-23 09:40:32

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

我正在尝试使用命令bundle exec rake assets:precompile在localhost上预编译资产,输出如下:

/Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr/local/mysql in PATH, mode 040777
/Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler.rb:263: warning: Insecure world writable dir /usr/local/mysql in PATH, mode 040777
/Users/adam/.rvm/rubies/ruby-1.9.3-p385/bin/ruby /Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler.rb:263: warning: Insecure world writable dir /usr/local/mysql in PATH, mode 040777
rake aborted!
Access denied for user 'root'@'localhost' (using password: YES)
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/model_schema.rb:308:in `clear_cache!'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activerecord-3.2.12/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:418:in `_run__4521211058967275969__prepare__3791545036321061180__callbacks'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/adam/rubydev/Fileito/config/environment.rb:5:in `<top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.12/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/adam/.rvm/rubies/ruby-1.9.3-p385/b...]
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `eval'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

我使用的是SQLite数据库,而不是MySQL - 为什么我不能预先编译资产?

2 个答案:

答案 0 :(得分:1)

将此行添加到config/application.rb

config.assets.initialize_on_precompile = false

它将阻止Rails在资产预编译时连接到DB。

答案 1 :(得分:-2)

我认为你应该修复

  

拒绝用户'root'@'localhost'

检查数据库配置文件并修复数据库连接问题,然后预编译资产