Rails 6: How to add jquery-ui through webpacker?

后端 未结 8 975
失恋的感觉
失恋的感觉 2021-01-05 04:12

I\'m currently trying to implement a datepicker into my application, the problem is that there is no documentation on how to add the jquery-ui-rails gem through

8条回答
  •  梦谈多话
    2021-01-05 04:40

    Kalman's answer worked for me, although not from the very beginning (I'm writing it in a separate answer as I don't have enough reputation to comment on the original answer yet :) )

    So, beware that when you put require("jquery-ui") in app/javascript/packs/application.js, the functions provided by jquery-ui will not be available in your scripts loaded to individual views with javascript_pack_tag

    The reason for that is that these individual scripts will load before application.js loads.

    To make it work, I had to put require("jquery-ui") in one of these individual scripts that depended on jquery-ui

    BTW, it works in Kalman's example, as he wrote his script directly in application.js, after requiring "jquery-ui"

提交回复
热议问题