I am building a website with Ruby on Rails, and I encountered a problem with including my javascript files into project. I have a script named init.js
in app/javascript
directory, and I want it to be included in all my views.
If I got it right, I need to use Asset Pipeline for this, so I wrote //= require init
in the app/javascript/application.js
file. However, when I go on the website, I can see, that application.js
is included in the sources tab, but init.js
is not:
Also I tried to write <%= javascript_include_tag "init" %>
in my layout head, and it worked, but if I understand correctly, it doesn’t use Asset Pipeline, so it’s not what I want.
By the way, asset pipeline worked as expected with CSS files: I just put all my CSS into app/assets/stylesheets
, and contents of all files got copied into application.css
, where I have *= require_tree .
.
Here’s contents of some files:
app/assets/config/manifest.js
:
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/assets/javascript .js
//= link_tree ../../../vendor/assets/stylesheets .css
app/javascript/application.js
:
import "@hotwired/turbo-rails"
import "controllers"
//= require init
What am i missing?