I've gone through a good chunk of this tutorial, and have gotten to the part where functionality for deleting articles is added:
https://guides.rubyonrails.org/getting_started.html
...but whenever the 'Delete' link is clicked on, the article is not deleted. Nothing happens, and a GET request is sent rather than a DELETE.
From the erb file:
<%= link_to 'Destroy', article_path(@article), data:{
turbo_method: :delete,
turbo_confirm: 'Are you sure?'
} %>
From the controller:
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to root_path, status: :see_other
end
After trying a solution that was mentioned in SO and in various Web pages (adding the below to my 'application.html.erb' file:
<%= javascript_include_tag 'application', "data-turbo-track": "reload" %>
...I get this error:
ActionView::Template::Error (The asset "application.js" is not present in the asset pipeline.
I did some digging and realized that the application scaffolder (rails new blog
in this case) didn't create any Javascript directories much less add any JS files to them. I'm fine with adding them myself, but I don't even know what JS files Rails and/or Turbo is looking for. JQuery? Some other library?
Ideally, however, I'd like to know how to properly scaffold an app so that any necessary Javascript is included.
Thanks, Bryan
EDIT I was able to get the delete functionality working by using the 'non-turbo' method of deleting items and using 'button_to' instead of 'link_to' for the 'Delete' link. However-- I would still like to know why the app as shown in the tutorial doesn't work as expected, and how to use a link rather than a button to trigger the item deletion (not to mention why using turbo doesn't work).
bin/dev
to start processes with foreman – Whisk