1

I'm working on upgrading an app to use Rails 3.1 and I'm trying to use the asset pipeline. As a test, I've added foobar.js to app/assets/javascripts.

The Setup

In application.rb, I've added config.assets.enabled = true. Going on this guide, I think that's all I have to do.

Checking it out

If I load the console and check Rails.application.config.assets.paths, I do see app/assets/javascripts in the load path. Also, if I check MyAppName::Application.assets, I get back a Sprockets::Environment object which has the same paths.

That all looks good to me.

Trying to use it

In a view, I'm using javascript_include_tag('foobar'). That outputs the following HTML: <script src="/javascripts/foobar.js" type="text/javascript"></script>

The error

Following that link gets me an error: No route matches [GET] "/javascripts/foobar.js"

Is there a piece of setup I'm missing?


Misc Details

I'm currently using:

  • ruby-1.9.2-p290
  • rails-3.1.0.rc6
  • sprockets-2.0.0.beta.14 (required by Rails)
Community
  • 1
  • 1
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
  • 1
    I still had to add the files manually to the pipeline (see https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/lib/gmaps4rails.rb). I guess it's because Rails 3.1 is still in beta – apneadiving Aug 25 '11 at 13:42
  • @apneadiving - progress! Doing that **does** get foobar.js loaded. Next I tried loading a manifest file, which has `//= require` statements in it. That file is sent to the browser without processing; the `require` statements are just treated as comments instead of processing the specified files. Ideas? – Nathan Long Aug 25 '11 at 13:52
  • mmm, don't know: it worked properly for me: https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/public/javascripts/gmaps4rails/googlemaps.js – apneadiving Aug 25 '11 at 15:00
  • @apneadiving - My boneheaded mistake. :) My manifest file had a dot in it, like `MyRailsEngine.manifest.js`. I think that made Rails/Sprockets try to processes it as a `manifest` file, which it doesn't know how to do. Not sure why it it didn't throw an error, but anyway, changing it to `MyRailsEngine-manifest.js` works fine. – Nathan Long Aug 25 '11 at 15:08
  • 1
    @apneadiving - So, basically, your first comment solved my problem. Want to add it as an answer so I can accept it? – Nathan Long Aug 25 '11 at 15:08
  • weird behavior yep! good to know though :) Did I answer your question? – apneadiving Aug 25 '11 at 15:09
  • damn we are connected ;) – apneadiving Aug 25 '11 at 15:09

1 Answers1

2

I still had to add the files manually to the pipeline (see link).

I guess it's because Rails 3.1 is still in beta

apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • Hey - I think we're actually doing this wrong. Your trick got things working for me, but I had my `application.js` in `public/javascripts/`, which we added to the load path in your initializer. When I moved the file to `app/assets/javascripts/`, I didn't need the initializer anymore, because `app/assets/javascripts/` was already on the load path. – Nathan Long Aug 26 '11 at 13:45
  • ok thanks :) Indeed, I keep everything in `public/javascripts` to maintain Rails 3.0.x compatibility – apneadiving Aug 26 '11 at 13:46