Yesterday everthing worked fine. Before i recover the last state I would like to understand what actually breaks jquery data-method: delete and routes it to show view. By now i dont even know if jquery is working at all. Lightbox is working well, but testing jquery like this: Testing jquery in Rails 6 gives me a hidden div.
Ive added jquery by "yarn add jquery" - no errors
Ive added to my application.js:
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("jquery")
require("channels")
require("packs/lightbox")
and this to my environment.js:
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.prepend('Provide', new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
}))
module.exports = environment
The first mysterious behavior was, that i had to create a lightbox.js file in my pack directory. It didn't work whith an simple import in application.js .
The next thing is, that my link_to for the delete-methods breaks and shows the show view:
<%= link_to 'Delete', gallery, :class => "btn btn-danger btn-sm text-white", method: :delete, data: { confirm: "Are you sure?" } %>
which gives me the correct html:
<a class="btn btn-danger btn-sm text-white" data-confirm="Are you sure?
This action will delete all image assignments to this gallery." rel="nofollow" data-method="delete" href="/galleries/21">Delete</a>
And here is the controller-method:
# DELETE /galleries/1
# DELETE /galleries/1.json
def destroy
@gallery.destroy
respond_to do |format|
format.html { redirect_to galleries_path, notice: 'Gallery was successfully deleted.' }
format.json { head :no_content }
end
end
But it directs to show view, so i dont even know if jquery is working because it looks like it would not and still lightbox is working. Yesterday the link_to worked fine.
Is there the possibility that somehow any manifest-files are broken?