0

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?

Spinshot
  • 275
  • 2
  • 12

2 Answers2

0

Add this to enviroment.js

Rails: ['@rails/ujs']
rhugo
  • 464
  • 1
  • 5
  • 15
0

I created a new project and added the files one by one from the old one to the new one. The new one works perfect but i only added jquery through yarn. So it seems, that if you install several versions of jquery (jquery gem / jquery-rails / jquery yarn) and switch or delete them, the basic rails/ujs looses its function in rails 6. I wasnt able to restore it in the old project, but its nice to know, that you have to be careful in rails 6 overwriting rails basic fuctionality.

Spinshot
  • 275
  • 2
  • 12