zoukankan      html  css  js  c++  java
  • Rails 4.0.0 开发环境一切正常,到生成环境发现 无法找到 css 和 js



    # Production  冰山一角的悲剧啊


    Started GET "/discount_service/assets/admin.js?body=1" for 127.0.0.1 at 2014-05-23 14:50:24 +0800
    
    ActionController::RoutingError (No route matches [GET] "/discount_service/assets/admin.js"):
      actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
      actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
      railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
      railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
      activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
      activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
      activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
      railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
      actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
      rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
      rack (1.5.2) lib/rack/runtime.rb:17:in `call'
      activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
      rack (1.5.2) lib/rack/lock.rb:17:in `call'
      actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
      railties (4.0.0) lib/rails/engine.rb:511:in `call'
      railties (4.0.0) lib/rails/application.rb:97:in `call'
      rack (1.5.2) lib/rack/content_length.rb:14:in `call'
      puma (2.6.0) lib/puma/server.rb:486:in `handle_request'
      puma (2.6.0) lib/puma/server.rb:357:in `process_client'
      puma (2.6.0) lib/puma/server.rb:250:in `block in run'
      puma (2.6.0) lib/puma/thread_pool.rb:92:in `call'
      puma (2.6.0) lib/puma/thread_pool.rb:92:in `block in spawn_thread'




    1.gemFile


    在rails 4 之后没有grop 了 要记得哦


    # group :assets do
    gem 'sass-rails', '~> 4.0.0'
    gem 'coffee-rails', '~> 4.0.0'    
    gem 'uglifier', '>= 1.3.0'
    # end
    # 页面渲染
    gem 'jquery-rails'  #这个
    gem 'execjs'      # 记得这个
    gem 'turbolinks'
    


    2.在 config/application.rb 记得 application 文件 不要对了哦

    config.assets.precompile << Proc.new do |path|
          if path =~ /.(css|js|scss|png|jpg|gif|json)z/
            full_path = Rails.application.assets.resolve(path).to_path
            app_assets_path1 = Rails.root.join('app', 'assets').to_path
            app_assets_path2 = Rails.root.join('public', 'assets').to_path
            app_assets_path3 = Rails.root.join('vendor', 'assets').to_path
    
    
            if full_path.starts_with? app_assets_path1
              true
            else
              if full_path.starts_with? app_assets_path2
                true
              else
                if full_path.starts_with? app_assets_path3
                  true
                else
                  false
                end
              end
            end
          end
        end
    


    3.秘诀 config/environment/production.rb


       config.action_controller.relative_url_root = '/discount_service'  #是用来 实用啊
       config.serve_static_assets = true
       # Compress JavaScripts and CSS.
      config.assets.compress = true
       config.assets.js_compressor = :uglifier
       config.assets.css_compressor = :sass

    4.最后要记得这个 啊 

    RAILS_ENV=production rake assets:precompile



      




  • 相关阅读:
    接口
    多态
    static的用法
    Person类中多个构造方法和测试
    曹操外卖实现功能
    曹操外卖数据表设计
    java中 try catch finally和return联合使用时,代码执行顺序的小细节
    GenerationType四中类型
    spring boot
    VMware修改为静态ip
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/6726116.html
Copyright © 2011-2022 走看看