Rails 3 Engine & Static assets

后端 未结 6 1994
南旧
南旧 2020-12-29 14:34

I\'m building an engine I\'ve bundled as a gem (gmaps4rails). I copied the /public of my engine in the /public of my rails app.

Everything works fine in development

相关标签:
6条回答
  • 2020-12-29 15:03

    In your engine, replace:

    initializer "static assets" do |app|
      app.middleware.use ::ActionDispatch::Static, "#{root}/public"
    end
    

    with:

    initializer "static assets" do |app|
          app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
    end
    
    0 讨论(0)
  • 2020-12-29 15:06

    I don't know much about the way, gems are packaged/made. But why can't you copy the images/js/css stuff of your gems public folder into the apps public folder? I just did that and it worked for me. Is that not the done thing?

    0 讨论(0)
  • 2020-12-29 15:13

    For performance reason, static assets serving is disabled in production mode. Your webserver should be configured to serve theses assets.

    Look at this discussion if your are using nginx as a webserver.

    0 讨论(0)
  • 2020-12-29 15:17

    In Rails 3.x try to set this in config/environments/production.rb

    config.serve_static_assets = true

    By default Rails assumes you are using an assets server (lightttp, nginx or Apache)

    0 讨论(0)
  • 2020-12-29 15:17

    I had a similar problem mounting a Rails 3.1 engine. I was receiving blank assets in stage and production.

    I found a solution at http://jonswope.com/2010/07/25/rails-3-engines-plugins-and-static-assets/comment-page-1/#comment-87 and tweaked it to suit Rails 3.1 asset locations:

    initializer "static assets" do |app|
      app.middleware.insert_before ::Rack::Lock, ::ActionDispatch::Static, "#{root}/app/assets"
    end
    

    I imagine there is a more elegant way but my effort today didn't yield anything substantial.

    0 讨论(0)
  • 2020-12-29 15:25

    Have you tried adding this to your Rails::Engine class:

    initializer "static assets" do |app|
      app.middleware.use ::ActionDispatch::Static, "#{root}/public"
    end
    

    This will merge in your Gem's /public directory with the app at runtime.

    0 讨论(0)
提交回复
热议问题