6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsでJavascript(jQuery)が画面遷移の時に動かないときは

Posted at

#現象
リロードするときはカレンダーが表示されるが、link_toから画面遷移すると遷移するとJavaScriptがうまく動作しない。

#原因
Railsのturbolinksという昨日が原因でした。

#自分の環境

Linux Debian 10.0(Docker上)
ruby 2.6.3p62
Rails 5.2.3

#対処法

application.js
$(document).ready(function(){

⬇︎

application.js
document.addEventListener("turbolinks:load", function() {

これによりturbolinksを無効にできました。

##別の対処法

<%= link_to "リンク名", 〇〇_path, data: {"turbolinks" => false} %>

これでもturbolinksを無効にできます。

#参考にさせていただいたサイト
https://qiita.com/hodosan/items/ee84482d18d6dccd9488
https://qiita.com/ryichiki/items/157b0f4288ce605de2a2
https://gist.github.com/saboyutaka/8727377

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?