Eugene
Eugene

Reputation: 689

Rails 6 does not see JS

I created new application. Installed bootstrap, jquery, popper via yarn add. Imported bootstrap .scss in app/assets/stylesheets/application.scss (and styles works fine).

Found problem with js. It seems like Rails does not see js at all.

What I did already: tried to import bootstrap and add simple jquery code into app/assets/javascript/packs/application.js, app/assets/javascript/application.js. Tried to create custom.js and require it in both application.js Changed javascript_tag in layout. I tried all recommendations from tutorials.

Everything without success. I have a hunch that somewhere js already accidentally compiled and any my edits in application.js useless for app. Is it possible?

I starting app in development mode via foreman Proc file.

web: bundle exec puma -C config/puma.rb
webpacker: ./bin/webpack-dev-server

What did I miss?

Thanks

Upvotes: 0

Views: 679

Answers (2)

Spinshot
Spinshot

Reputation: 315

There are some dependencies, which you have to add to make things work. I could write every step down, but there is a nice tutorial, which will walk you through step by step: Add Bootstrap 4 to your Ruby on Rails 6 application

Upvotes: 0

Clara
Clara

Reputation: 2715

Rails 6 uses webpacker to bundle JS code by default. So JS is not bundles throught the asset pipeline anymore (it used to live in app/assets/javascript. The new folder lives directly under app, so: app/javascript. Also you require JS now with the javascript_pack_tag!

Read more here: https://prathamesh.tech/2019/08/26/understanding-webpacker-in-rails-6/

If you want to make bootstrap work (and you already installed it via yarn), import it in app/javascript/application.js

import "bootstrap";

Upvotes: 2

Related Questions