我已经看过几篇类似的帖子,但没有解决方案,所以我想我会提出一个更有记录的问题.
在本地运行我的服务器,并打开JS文件时,我看不到任何编译,只是标准的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_ujs //= require underscore //= require backbone //= require backbone_rails_sync //= require backbone_datalink //= require backbone/myapp //= require_tree .
我的开发.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
我的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
我的日志:
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)
需要注意的是,当我从MongoDB构建迁移到Postgres构建时,这个应用程序是从另一个应用程序中挑选出来的.所以我认为很可能,这与一些未经挑选的细节有关.
这个问题可以通过做..
> $rvm使用ruby-2.0.0-p0
> $rails新项目
>在/ assets / javascripts /中创建一个带有alert(‘hey’)的javascript文件
> $rails s
我认为这个问题是因为Ruby 2还没有与Rails一起使用:(
我将此正式定位为Ruby 2与Rails 3.2.6不兼容
解决方法
Rajesh的解决方案也对我有用.
我正在使用2.0.0-p195和rake资产:生产时的预编译并没有真正读取application.js而我最终得到了文件应用程序 – ###.js,大小为1kb.
我正在使用2.0.0-p195和rake资产:生产时的预编译并没有真正读取application.js而我最终得到了文件应用程序 – ###.js,大小为1kb.
所以我回到了ruby 1.9.3,更新了捆绑包,手动清除了缓存
rm -rf tmp/cache/assets/* rm -rf tmp/cache/sass/*
然后
在我的application.js中,我有
//= require jquery //= require bootstrap //= require_tree .
请注意,我不使用jquery-ui或jquery_ujs
然后我跑了
rake RAILS_ENV=production RAILS_GROUP=assets assets:clean rake RAILS_ENV=production RAILS_GROUP=assets assets:precompile
现在它有效.