我正在构建一个相对较新的Rails 5应用程序。我一直在使用bootsy
宝石,而且我一直遇到一个问题,即在页面刷新之后,wysiwyg才会在页面上显示。在玩了一段时间之后,我发现如果我从turbolinks
中删除了application.js
,则第一次出现所见即所得(没有页面刷新)。任何人都可以告诉我应该如何turbolinks
进入我的application.js
。提前谢谢。
的application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap-sprockets
//= require bootsy
//= require turbolinks
//= require_tree .

application.scss:
@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootsy";
@import "articles";

的Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-turbolinks'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'simple_form'
gem 'bootstrap-sass'
gem 'bootsy'

我将simple_form
与bootsy
结合使用,所以我的表单看起来像这样:
<%= simple_form_for @article, url: action_path do |f| %>
<%= f.input :title %>
<%= f.input :body, label: "Article Body", as: :bootsy %>
<%= f.submit %>
<% end %>
&#13;
答案 0 :(得分:0)
您需要使用turbolinks:load
这样的事件:
$(document).on('turbolinks:load', ready)
function ready() {
//your code here
}
您的要求没问题。
就是这样。
答案 1 :(得分:0)
所以经过一段时间的游戏,我找到了解决方案。我向document.addEventListener('turbolinks:load', Bootsy.init);
添加了application.js
,这解决了问题。