Javascript不能在Ruby on Rails部署模式下工作

Javascript not working in Ruby on Rails Deployment mode

本文关键字:部署 模式 工作 Rails on 不能 Ruby Javascript      更新时间:2023-09-26

当我的Ruby on Rails项目处于部署模式时,我无法获得任何javascript运行。我有一个js在vendor/assets/javascript/theme/index-slider.js。它在这个文件中有一个警告来测试javascript是否正常工作:

alert('TestTestTest');

当我在开发模式下运行项目时,所有javascript都正常运行。此外,如果我将<script>alert("Testme");</script>添加到我的index.html.erb文件中,该javascript将在生产模式下运行。

我一直在运行rake assets:precompileRAILS_ENV=production rake assets:precompile时进行更改以及重新启动服务器

如何让Javascript在生产模式下运行?(另外,我对Ruby on Rails相当陌生,所以我不确定我应该包括哪些文件/信息来帮助。)谢谢。

application.js

// 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 vendor/assets/javascripts of plugins, if any, 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/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap/bootstrap
//= require theme/bootstrap.min
//= require theme/flexslider
//= require theme/index-slider
//= require theme/jquery.countdown.min
//= require theme/jquery.isotope.min
//= require theme/theme
//= require_tree .

我发现问题在于application.js文件。我已经添加了bootstrap到我的项目手工以及bootstrap主题。我发现,无论出于何种原因,//= require bootstrap/bootstrap行不应该包含在我选择的主题之上。

您还需要为您的产品编译资产

rake assets:precompile RAILS_ENV=production