All threads / public/javascript/lib files not available in production

Ask A Question

Notifications

You’re not receiving notifications from this thread.

public/javascript/lib files not available in production

jason Mardell asked in Rails

I have added some javascript files to pubic/javascripts/lib and I have referenced them thus

... type="text/javascript" src="/javascripts/lib/add_all_plots.js" ...

They can be loaded in dev no problem. In production they are not available at that url and don't load.

I must be missing something somewhere? A secret handshake maybe? A special spell?

Any help much appreciated

Hey Jason,

That looks correct. Any static files you don't want going through the asset pipeline or webpacker would go in public somewhere and you would just link to it accordingly (minus the public of course).

What's your production javascript console say? It can't find /javascripts/lib/add_all_plots.js?

No secret handshakes, but I kinda wish there was now...

I just get a 404 when I link to /javascripts/lib/add_all_plots.js?

I don't have easy access to the production javascript console - what should I be looking for on there please?

Hey Jason, the Javascript console is just the one in your browser.

Anyways, what if you try putting your javascript file in the asset pipeline and requiring it in your application.js so you go through the standard Rails javascript includes?

Thanks Chris - looks like the solution is to add

config.serve_static_files = true

to production.rb

Ah yeah, you would need that if you're on Heroku. I use NGINX on my own server which automatically serves static files, so that would make sense. Hah!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.