我的Rails Javascript清单文件既不编译也不包含任何必需的文件 [英] My Rails Javascript manifest file neither compiles nor include any required files

查看:52
本文介绍了我的Rails Javascript清单文件既不编译也不包含任何必需的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过几篇类似的文章,但没有解决方案,所以我认为我会提出一个更有据可查的问题.

I've seen a few posts similar to this but with no solutions, so I figured I would present a more documented problem.

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

My Problem JS from manifest file is not including or compiling any JS.

在本地运行服务器并打开JS文件时,我看不到任何编译内容,只有标准的application.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 .

我的development.rb:

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

我的application.rb:

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

我的日志:

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构建时,该应用是从另一个应用中挑选的.因此,我认为这很可能与某些未经挑选的细节有关.

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 ..

  1. $ rvm use ruby-2.0.0-p0
  2. $ rails new project
  3. /assets/javascripts/
  4. 中使用alert('hey')创建一个javascript文件
  5. $ rails s
  1. $ rvm use ruby-2.0.0-p0
  2. $ rails new project
  3. Create a javascript file with alert('hey') in it in /assets/javascripts/
  4. $ rails s

我认为这个问题是因为Ruby 2尚不能与Rails一起使用:(

I think this issue is because Ruby 2 does not work with Rails yet :(

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

I have this officially pinpointed as Ruby 2 in incompatible with Rails 3.2.6

推荐答案

Rajesh的解决方案也对我有用. 我当时使用2.0.0-p195和rake资产:在生产中进行预编译并没有真正读取application.js,结果我得到了文件application-###.js,大小为1kb.

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.

所以我回到了ruby 1.9.3,更新了包,并通过

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

然后

在我的application.js中,我有

in my application.js, I have

//= require jquery
//= require bootstrap
//= require_tree .

请注意,我不使用jquery-ui或jquery_ujs

note that I don't use jquery-ui or jquery_ujs

然后我跑了

rake RAILS_ENV=production RAILS_GROUP=assets assets:clean
rake RAILS_ENV=production RAILS_GROUP=assets assets:precompile

现在可以使用了.

这篇关于我的Rails Javascript清单文件既不编译也不包含任何必需的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆