Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails can't start when serve_static_assets disabled in production

The site works fine until I add config.serve_static_assets = false in my production.rb. Then I just get this:

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>'

Specifically in my development.rb I have these settings regarding the assets:

# 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

Any help would be appreciated.

like image 622
newUserNameHere Avatar asked May 31 '15 22:05

newUserNameHere


1 Answers

The problem was this line in my engine.rb (I'm running a rails engine in a custom gem).

app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")

I wrapped the line with this if statement and now everything is working:

if Rails.application.config.serve_static_assets 
  app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
end
like image 119
newUserNameHere Avatar answered Nov 07 '22 22:11

newUserNameHere