1

I'm upgrading a rails 2.3.9 application and I have a file named widget.js that lives at /public/javascripts/widget.js.

Users can embed this javascript widget on their own site like so:

<script src='http://example.com/javascripts/widget.js' type='text/javascript'></script>
<script>
  new Widget({user_id: 1234});
</script>

As I understand it, with Rails 3.1 everything under assets/ is fingerprinted in production so widget.js would have a filename like widget-XXXYYYZZZ.js and would change every time the file was changed. This means that it wouldn't be possible to give users this embeddable url for the widget.js file since it'll change.

How can this be accomplished on rails 3.1?

markquezada
  • 8,444
  • 6
  • 45
  • 52

2 Answers2

3

You could just leave your script in public/javascripts/widget.js and serve it from /javascripts/widget.js. The asset pipeline is optional, you don't have to use it for everything (or anything for that matter).

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • Interesting. I had originally tried this using the javascript_path helper in a view and it wasn't returning the reference to the right file. I'm guessing the javascript_path method is only returning files in `/assets/` and not in `/public/javascripts/`. Worst case scenario... I can generate the url to `/javascripts/widget.js` myself I guess. – markquezada Oct 11 '11 at 07:00
  • @mirthlab: The worst cast scenario isn't that bad for just one file. You could also add your own helper that knows about your exceptions and punts to `javascript_path` for the rest. – mu is too short Oct 11 '11 at 07:16
  • Yeah, great advice all around. Thanks for helping me think this through. – markquezada Oct 11 '11 at 07:20
0

You can disable fingerprinting by putting

config.assets.digest = false  

in config/application.rb or in one of the config/environments/* files.

rweng
  • 6,736
  • 7
  • 27
  • 30
  • I don't want to disable fingerprinting completely. It's useful for what it's meant to do. I want to know how to take what was working before and implement it in a way that is compatible with the asset pipeline and file fingerprinting. If I could disable the digest on a _per file_ basis then this might work. – markquezada Oct 11 '11 at 06:17