0

我已经完成了这个命令

bundle exec rake assets:precompile RAILS_ENV=production

现在,加载页面时不会启动已加载的 jQuery:( 在预编译之前它曾经可以正常工作...

可能的原因是什么?

资产/javascripts/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()});

资产/javascripts/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
// 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)
4

1 回答 1

3

我也在我的项目中使用 jquery,它工作正常

在生产上也

这是我的 application.js 内容

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

我想添加//= require_tree 。可能会解决问题请尝试一次并回复....

于 2013-04-25T06:16:47.983 回答