Q:

File-specific JavaScript in Rails

Right now, in my Rails project, I have in app/views/layouts the file application.html.erb
<head>
  ...
  <%= yield :javascript_includes %>
  <%= csrf_meta_tag %>
</head>

This includes all the JavaScript files in public/javascripts in all HTML pages.
Now, I have in app/views/dogs the file new.html.erb. I want to include a JavaScript file that is specific to this HTML file. Where should I put the JavaScript, and how can I include it?

A:

You can create a new javascript file in /app/assets/javascripts then include it on your dogs/new page with <%= javascript_include_tag "dogs.js" %>.

