OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Rails How to get Javascript working without webpack

  • Thread starter Thread starter John Cowan
  • Start date Start date
J

John Cowan

Guest
I'm running rails 6.1.7.6 and ruby 3.1.1

I'm set up a new rails app on heroku. I tried for two days to get webpack working but I couldn't. I followed many threads, but it kept saying I needed to install the webpack-cli. I had it installed, but the app just wouldn't see it. So I'm trying to get javascript working without it. I followed a couple of threads that said to do these steps:

Code:
# app/assets/config/manifest.js

//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_directory ../javascript .js   <-- I added this line

I created an application.js in app/assets/javascript/

Code:
# app/assets/javascript/application.js

//
//= require jquery3
//= require jquery-ui
//= require jquery_ujs
//= require turbolinks
//= require_tree
//= require dataTables/jquery.dataTables
//= require activestorage

$(document).ready(function() {
  alert("What the What?");
});

Code:
# views/layouts/application.html.erb
# this next line was:

 <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>

The javascript_include_tag causes an error. I read in a thread stating to change this to:

Code:
<%= javascript_tag "application", 'data-turbolinks-track' => true %>

Code:
# Gemfile:

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails', '~> 5.0.4'
gem 'jquery-datatables-rails'

But my views do not see my application.js.

Any ideas on how to get this to work?

<p>I'm running <code>rails 6.1.7.6</code> and <code>ruby 3.1.1</code></p>
<p>I'm set up a new rails app on heroku. I tried for two days to get webpack working but I couldn't. I followed many threads, but it kept saying I needed to install the webpack-cli. I had it installed, but the app just wouldn't see it. So I'm trying to get javascript working without it. I followed a couple of threads that said to do these steps:</p>
<pre><code># app/assets/config/manifest.js

//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_directory ../javascript .js <-- I added this line
</code></pre>
<p>I created an application.js in <code>app/assets/javascript/</code></p>
<pre><code># app/assets/javascript/application.js

//
//= require jquery3
//= require jquery-ui
//= require jquery_ujs
//= require turbolinks
//= require_tree
//= require dataTables/jquery.dataTables
//= require activestorage

$(document).ready(function() {
alert("What the What?");
});
</code></pre>
<pre><code># views/layouts/application.html.erb
# this next line was:

<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
</code></pre>
<p>The <code>javascript_include_tag</code> causes an error. I read in a thread stating to change this to:</p>
<pre><code><%= javascript_tag "application", 'data-turbolinks-track' => true %>
</code></pre>
<pre><code># Gemfile:

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails', '~> 5.0.4'
gem 'jquery-datatables-rails'
</code></pre>
<p>But my views do not see my <code>application.js</code>.</p>
<p>Any ideas on how to get this to work?</p>
 

Latest posts

Top