Ruby on Rails提交按钮仅适用于刷新

时间:2017-09-15 16:25:53

标签: javascript ruby-on-rails ruby turbolinks

基本上我有一个b_page的显示页面,我已经在内部呈现了一个新的部分(对于page_posts),只有刷新页面或者从浏览器直接打开链接时,它的提交按钮才有效。我已经检查过,没有丢失的div或未打开的标签等,因此它不是HTML问题。

也许这是一个Turbolinks问题导致这种情况几乎发生在所有应用中,如果是这样,我的application.js.erb

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.ui.all
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-tagsinput
//= require sync
//= require masonry/jquery.masonry
//= require jscolor
//= require_tree .
//= require owl.carousel
//= require turbolinks

我该如何解决这个问题?这是指向show.html.erb的链接。

1 个答案:

答案 0 :(得分:1)

您必须使用$(document).on('ready', function(){})

将其更改为$(document).on('turbolinks:load', function (){}),这会强制JavaScript在查看页面时加载。