问题
I've seen a few posts similar to this but with no solutions, so I figured I would present a more documented problem.
My Problem JS from manifest file is not including or compiling any JS.
When running my server locally, and opening the JS file I see nothing compiled, just the standard application.js manifest file :
// 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_ujs
//= require underscore
//= require backbone
//= require backbone_rails_sync
//= require backbone_datalink
//= require backbone/myapp
//= require_tree .
My development.rb :
MyApp::Application.configure do
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true
end
My application.rb :
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module MyApp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.enabled = true
config.assets.version = '1.0'
end
end
My Log :
Started GET "/questions" for 127.0.0.1 at 2013-04-04 08:56:09 -0400
Processing by QuestionsController#index as HTML
Completed 200 OK in 204ms (Views: 16.0ms | ActiveRecord: 17.4ms)
Started GET "/assets/application.css" for 127.0.0.1 at 2013-04-04 08:56:09 -0400
Served asset /application.css - 304 Not Modified (2ms)
Started GET "/assets/application.js" for 127.0.0.1 at 2013-04-04 08:56:09 -0400
Served asset /application.js - 304 Not Modified (0ms)
Started GET "/assets/favicon.png" for 127.0.0.1 at 2013-04-04 08:56:09 -0400
Served asset /favicon.png - 304 Not Modified (0ms)
To note , this app was cherry picked from another app as I migrated from a MongoDB build to a Postgres build. So I think that very likely, this has something to do with some uncherrypicked detail.
This issue can be reproduced by doing ..
$ rvm use ruby-2.0.0-p0
$ rails new project
- Create a javascript file with
alert('hey')
in it in/assets/javascripts/
$ rails s
I think this issue is because Ruby 2 does not work with Rails yet :(
I have this officially pinpointed as Ruby 2 in incompatible with Rails 3.2.6
回答1:
Rajesh's solution did work for me too. I was using 2.0.0-p195 and rake assets:precompile on production didn't really read application.js and I ended up having the file application-###.js with the size of 1kb.
So I went back to ruby 1.9.3, updated the bundle, cleared the cache manually by
rm -rf tmp/cache/assets/*
rm -rf tmp/cache/sass/*
and then
in my application.js, I have
//= require jquery
//= require bootstrap
//= require_tree .
note that I don't use jquery-ui or jquery_ujs
then I ran
rake RAILS_ENV=production RAILS_GROUP=assets assets:clean
rake RAILS_ENV=production RAILS_GROUP=assets assets:precompile
Now it works.
回答2:
I had the same problem, took long time to find a solutions to this.
I just switched back to ruby-1.9.3-p429
, and it resolved the problem. I don't know how to manage it with ruby 2 patches
. I have used ruby-2.0.0-p247
and ruby-2.0.0-p195
.
So, just do rvm use ruby-1.9.3-p429
. Then run 'bundle update'. Then clear the Rails cache by running Rails.cache.clear
in the console and also don't forget to clear the browser cache.
Hope it goes fine. :)-
来源:https://stackoverflow.com/questions/15811889/my-rails-javascript-manifest-file-neither-compiles-nor-include-any-required-file