gpt4 book ai didi

ruby-on-rails - 我的 Rails Javascript list 文件既不编译也不包含任何必需的文件

转载 作者:行者123 更新时间:2023-12-04 07:35:25 26 4
gpt4 key购买 nike

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

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

在本地运行我的服务器并打开 JS 文件时,我看不到任何编译内容,只有标准的 application.js list 文件:

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

这个问题可以通过做..
  • $ rvm use ruby-2.0.0-p0
  • $ rails new project
  • 使用 alert('hey') 创建一个 javascript 文件在其中 /assets/javascripts/
  • $ rails s

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

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

    最佳答案

    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

    现在它起作用了。

    关于ruby-on-rails - 我的 Rails Javascript list 文件既不编译也不包含任何必需的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15811889/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com