簡體   English   中英

Javascript無法在Ruby on Rails部署模式下工作

[英]Javascript not working in Ruby on Rails Deployment mode

當我的Ruby on Rails項目處於部署模式時,我無法運行任何javascript。 我在vendor / assets / javascript / theme / index-slider.js上有一個js。 它在此文件中有一個警報來測試javascript是否正常工作:

alert('TestTestTest');

當我在開發模式下運行項目時,所有的javascript都正常運行。 另外,如果我將<script>alert("Testme");</script>到我的index.html.erb文件中,那javascript將以生產模式運行。

我一直在運行rake assets:precompileRAILS_ENV=production rake assets:precompile在進行更改時重新RAILS_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添加到我的項目中以及boostrap主題。 我發現無論出於何種原因,// = require bootstrap / bootstrap行不應該包含在我選擇的主題之上。

您還需要為您的生產編譯資產

rake assets:precompile RAILS_ENV=production

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM