We are using Rails 5.2 at work and the asset pipeline has been removed. As a Rails newbie I keep coming across problems with methods not working as I expect.
For example the following link_to
extract is processed as a GET request rather than DELETE and the confirmation is not shown.
<%=link_to 'Delete', admin_enhanced_object_media_item_path(@enhanced_object, media_item), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn--danger' %>
The following SO Q&A helped me understand that it related to a missing rails-ujs or jquery dependency and I was able to recover part of the functionality by replacing with button_to
.
Rails' link_to method: GETing when it should DELETE
This sorted the method error but still doesn't show the confirmation alert.
I can see the missing methods in the Rails sourcecode (coffeescript) https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts/rails-ujs/features
Given that I am not able to install rails-ujs am I able to replace these helper methods with vanilla JS in my application javascript files. Can anyone point me to an example of where this has been done or explained? I expect others work without the Rails asset pipeline but would like to maintain access to the unobtrusive javascript helpers listed here: https://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers