I'm in the process of trying to upgrade my app to Rails 3.1, and I have quite a lot of custom Javascript files that I'm trying to migrate to the new assets pipeline.
My current (that is, pre-3.1) directory structure has something like:
public/
foo/
model.js
controller.js
etc...
So, I'm trying to move these to lib/assets/javascripts and keep the foo/ subdirectory intact (rather than make foo_model.js, foo_controller.js, etc).
In my application.js I tried to do:
//= require foo/model
and
//= require 'foo/model'
But these don't work. Rails always gives me an error page and says:
couldn't find file 'foo/model.js'
I did test that things get correctly included if they're not in the subdirectory, so I know it's not just that my lib/assets directory is not in the include path or something. So I guess I'm just wondering if there's a way to do this, or should I just be flattening the directories and using foo_model.js and such?
Looks like rails only add one level of subdirectories to assets paths
You can check with current paths by running Rails.application.config.assets.paths
at rails console
add absolute path of your folders at application.rb like
config.assets.paths += ["/path/to/lib/assets/javascript/foo"]
Not sure why rails only adds one level of subdirectories, but you can surely add additional (fully qualified) paths to the pipeline in config/application.rb. The docs lead to the answer: http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
For example:
config.assets.paths << "#{Rails.root}/app/assets/flash"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With