8

我看过一些类似的帖子,但没有解决方案,所以我想我会提出一个更多记录的问题。

清单文件中的我的问题JS 不包含或编译任何 JS。

在本地运行我的服务器并打开 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 .

我的 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

我的 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 构建时,这个应用程序是从另一个应用程序中挑选出来的。所以我认为这很可能与一些未经挑选的细节有关。

可以通过执行此问题来重现此问题 ..

  1. $ rvm use ruby-2.0.0-p0
  2. $ rails new project
  3. alert('hey')在其中创建一个javascript文件/assets/javascripts/
  4. $ rails s

我认为这个问题是因为 Ruby 2 还不能与 Rails 一起工作:(


我已将其正式确定为与 Rails 3.2.6 不兼容的 Ruby 2

4

2 回答 2

5

Rajesh 的解决方案也对我有用。我使用的是 2.0.0-p195 和 rake assets:precompile on production 并没有真正读取 application.js,我最终得到了大小为 1kb 的文件 application-###.js。

所以我回到 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

现在它起作用了。

于 2013-07-29T07:16:31.890 回答
3

我遇到了同样的问题,花了很长时间才找到解决方案。

我刚刚切换回ruby-1.9.3-p429,它解决了问题。我不知道如何管理它ruby 2 patches。我用过ruby-2.0.0-p247ruby-2.0.0-p195

所以,就做吧rvm use ruby-1.9.3-p429。然后运行“捆绑更新”。然后通过在控制台中运行来清除 Rails 缓存,Rails.cache.clear并且不要忘记清除浏览器缓存。

希望一切顺利。:)-

于 2013-07-17T06:24:06.950 回答