A
A
aaltw2022-02-11 09:54:57
Ruby on Rails
aaltw, 2022-02-11 09:54:57

How to make code from application.js run before code from .html.slim files in Rails 7?

Used importmaps, made pin jquery, in application.js did:

import jquery from 'jquery';
  window.$ = jquery;


For example, index.html.slim uses $:
h1 Hello

  javascript:
    $('h1').hide();


But I get an error that $ is not defined. Most likely just because index.html.slim was executed before application.js. Because after the console everything works as it should.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question