I am very new to Ruby and Ruby on Rails. Currently, I am using Ruby 3 and Rails 7. In my project, I want to add some javascript files required for Bulma CSS to work correctly. I learned how to do this with the help of import maps. But then I noticed that the link_to helper for delete throws a get request instead of delete. I figured out that somehow the turbo method is not working. Here are are the following files.
app/javascript/application.js
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails";
import "controllers";
import "bulma_css_helper/navbar_toggler";
import "bulma_css_helper/notification_toggler";
config/importmap.rb
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from "app/javascript/bulma_css_helpers", under: "bulma_css_helpers"
delete button
<%= link_to tweet_path(tweet), data: { turbo_method: :delete, turbo_confirm: "Are you sure?" }, class: "has-text-danger" do %>
<span class="icon">
<i class="fa-solid fa-trash-can"></i>
</span>
<% end %>
I tried to use button_to helper it works but does not send any confirm requests.
<%= button_to tweet_path(tweet), method: :delete, form: { data: { turbo_confirm: "Are you sure?" } }, class: "has-text-danger" do %>
<span class="icon">
<i class="fa-solid fa-trash-can"></i>
</span>
<% end %>
Update: I also received an error in the console.
Uncaught TypeError: Failed to resolve module specifier "bulma_css_helper/navbar_toggler". Relative references must start with either "/", "./", or "../".
I would also like to point out that when I tried to log all the imports using ./bin/importmap json
this is what I am getting.
{
"imports": {
"application": "/assets/application-92da2dacddd68d3c4d65944d44e99cc38a1b350ca0f2d2707314a20f8f021328.js",
"@hotwired/turbo-rails": "/assets/turbo.min-f309baafa3ae5ad6ccee3e7362118b87678d792db8e8ab466c4fa284dd3a4700.js",
"@hotwired/stimulus": "/assets/stimulus.min-d03cf1dff41d6c5698ec2c5d6a501615a7a33754dbeef8d1edd31c928d17c652.js",
"@hotwired/stimulus-loading": "/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js",
"rails-ujs": "https://ga.jspm.io/npm:rails-ujs@5.2.8-1/lib/assets/compiled/rails-ujs.js",
"controllers/application": "/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js",
"controllers/hello_controller": "/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js",
"controllers": "/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js"
}
}
which clearly doesn't import any of the files within bulma_css_helper
.
What should be the correct approach?