Javascript 代码在 Rails 的 Ruby 中不起作用

Javascript code not working in Ruby on Rails

我正在尝试用这个做我的前端 Codepen Template but when i'm trying to click on the signup button, it's not changing to signup form for which the code is in the index.js file, i've included hte index.js file in the login.html.erb but when i'm running the rails server the transition isn't working. My Rails Project, Codepen Template 这是 index.js

中的 javascript 代码
document.querySelector('.img__btn').addEventListener('click', function() {
document.querySelector('.cont').classList.toggle('s--signup');  });

将您当前的 JS 代码包装在 app/assets/javascripts/application.jsDOMContentLoadListener 事件监听器:

document.addEventListener('DOMContentLoaded', function() {
  document.querySelector('.img__btn').addEventListener('click', function() {
    document.querySelector('.cont').classList.toggle('s--signup');
  });
});

尝试更改 index.js 的路径 在 app.html 中添加此行以包含索引 js 文件。

<%= javascript_include_tag "index" %>