cat
cat

Reputation: 749

Why jQuery won't work on rails?

I've done this command

bundle exec rake assets:precompile RAILS_ENV=production

Now, loaded jQuery won't be started when page is loaded:( It used to work fine before precompiling...

What could be the possible reason?

assets/javascripts/refresh_count.js

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


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

view

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

generated HTML

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

the content of "/assets/refresh_count-0cdf67811wb7eavf438be9c8b8cc932bf.js"

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

assets/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

It's also saying this when executing precompile does this matter???

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)

Upvotes: 0

Views: 189

Answers (1)

Grey
Grey

Reputation: 676

I am using jquery in my project also and it works fine

on production also

Here is my application.js content

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

I think adding //= require_tree . may solve problem pls try it once and reply....

Upvotes: 3

Related Questions