2013-04-25 47 views
0

我做這個命令爲什麼jQuery不能在rails上工作?

bundle exec rake assets:precompile RAILS_ENV=production 

現在,當加載頁面加載:( 它使用預編譯之前,做工精細jQuery將無法啓動......

可能是什麼可能原因是什麼?

資產/ Java腳本/ refresh_count.js

jQuery(document).ready(function() { 
     refreshPartialMail(); 
    }); 


    function refreshPartialMail() { 
     $.ajax({ 
     url: "/messages/refresh_part", 
     type: "GET", 
     dataType: "script", 
     }); 
    } 

視圖

... 
<%= javascript_include_tag 'refresh_count' %> 
... 

生成的HTML

<script src="/assets/refresh_count-0cdf67811wb7eavf438be9c8b8cc932bf.js" type="text/javascript"></script> 

的內容 「/assets/refresh_count-0cdf67811wb7eavf438be9c8b8cc932bf.js」

function refreshPartialMail(){$.ajax({url:"/messages/refresh_part",type:"GET",dataType:"script"})}jQuery(document).ready(function(){refreshPartialMail()}); 

資產/ Javascript角/應用.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 
// the compiled file. 
// 
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 
// GO AFTER THE REQUIRES BELOW. 
// 
//= require jquery 
//= require jquery-ui 
//= require twitter/bootstrap 
//= require jquery_ujs 
//= require jquery.ui.datepicker 
//= require autocomplete-rails 

它也說這句話的時候執行precompile做這件事???

DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /var/www/html/sampleapp/Rakefile:7) 
+0

請幫助.... – cat 2013-04-25 04:08:34

+1

您是否使用'prototype'&'jQuery'兩種,如果是這樣'用'jQuery'替換$。 ajax'到'jQuery.ajax' beacuase有時它與原型衝突 – Salil 2013-04-25 04:50:09

+0

@Sali謝謝回覆:)我沒有使用'prototype' – cat 2013-04-25 08:12:33

回答

3

我在我的項目使用jQuery也和它的作品對生產也

這裏細

是我的application.js內容

//= require jquery 
//= require jquery_ujs 
//= require bootstrap 
//= require tinymce 
//= require_tree . 

我認爲加上// = require_tree。可能會解決問題請嘗試一次,並回復....

+0

謝謝。我試過,但沒有幫助:( – cat 2013-04-25 08:20:17

+0

嘿一個快速建議,如果你使用Firefox試試螢火蟲,並檢查控制檯,如果有任何錯誤或衝突存在...... – Magnum 2013-04-25 15:09:35

+0

我檢查了它在FireFox的Web控制檯之前,我可以看到javascript被調用在後臺,但現在,沒有出現在Web控制檯:( – cat 2013-04-25 15:16:58

相關問題