I am trying to put a nested form into one of my views. I have installed the nested_form Gem and performed the installation steps. The last thing I did was edit my app/view/layouts/application.html.erb file to include this line
<%= javascript_include_tag "nested_form" %>
But when I look at the rendered page, the javascript doesn’t work. I examined the page source and saw that the rendered code for the nested_form javascript looks like this:
<script src="/assets/nested_form.js" type="text/javascript"></script>
So it appears to be looking in the wrong place. That .js file is located in public/javascripts, not in assets. Did I do something wrong or do I need to specify something else in that javascript_include_tag?
From rails 3.1 and onwards, javascript_include_tag will only look in the asset pipeline for javascripts. If you want to add public/javascripts into your asset pipeline, simply add the public path to your
array when you initialize your RoR application, since defines the paths the asset pipeline looks at.
So no you did not do anything wrong, the gem you are using is just outdated and it’s for rails 3.0-. Although I recommend try moving the javascripts from the public folder to the assets folder and see if it works, because that is the preferred way to put javascripts in a 3.1 application.
Another way to solve your problem, though not recommended, is to disable the asset pipeline altogether, if you are not using it. This is done by removing
in your config/application.rb
If you want to know more about the asset pipeline, Railscasts has a video on it
http://railscasts.com/episodes/279-understanding-the-asset-pipeline