I'm following a Rails Tutorial | Building a Link Shortener with Rails 6 and ruby 2.xx to build the same app. However, I'm using rails 7.0.4 and ruby 3.0.0. My create.js.erb file does not work. And from a quick lookup on google, I discovered .js.erb has been removed from rails 7 and replaced with turbo_stream and hot stimulus.js.
How do I hook my code in create.js.erb which is embedded ruby in javascript into the new rails 7 say links_controller.js under javascript >> controller directory. since the latter is purely javascript.
create.js.erb:
var lookupCode = "<%#= @link.lookup_code %>";
var element = document.getElementById('short-link');
element.innerHTML = lookupCode;
I created this file under javascript >> controller directory: links_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
connect() {
this.element.textContent = "I believe I should hook the content of create.js.erb here";
}
}
Pls, any help will be greatly appreciated. I did a lot of research and googling before asking this question. And the only one that could have answered my question was closed:
Ruby on Rails 7 - Is there any way to implement js.erb files?