在我的production.rb中添加config.serve_static_assets = false
之前,该网站正常运行。然后我就明白了:
demosite.com(master)$ RAILS_ENV=production rails s
WARNING: Use strings for Figaro configuration. false was converted to "false".
=> Booting Puma
=> Rails 4.1.4 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/user1/.rvm/gems/ruby-2.2.1/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:125:in `assert_index': No such middleware to insert before: ActionDispatch::Static (RuntimeError)
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:88:in `insert'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/configuration.rb:68:in `block in merge_into'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/configuration.rb:67:in `each'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/configuration.rb:67:in `merge_into'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/engine.rb:497:in `app'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/application/finisher.rb:36:in `block in <module:Finisher>'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /Users/user1/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
from /Users/user1/Documents/rails/directory-project/demosite.com/config/environment.rb:5:in `<top (required)>'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/user1/Documents/rails/directory-project/demosite.com/config.ru:3:in `block in <main>'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:55:in `instance_eval'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:55:in `initialize'
from /Users/user1/Documents/rails/directory-project/demosite.com/config.ru:in `new'
from /Users/user1/Documents/rails/directory-project/demosite.com/config.ru:in `<main>'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:49:in `eval'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:49:in `new_from_string'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:40:in `parse_file'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:199:in `app'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands/server.rb:50:in `app'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:314:in `wrapped_app'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:250:in `start'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands/server.rb:69:in `start'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:81:in `block in server'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/user1/.rvm/gems/ruby-2.2.1/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
特别是在我的development.rb中,我有关于资产的这些设置:
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = false
任何帮助都将不胜感激。
答案 0 :(得分:2)
问题在于我的engine.rb中的这一行(我在自定义gem中运行rails引擎)。
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
我用if语句包装了这一行,现在一切正常:
if Rails.application.config.serve_static_assets
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
end