Rails 4.0.0 開發環境一切正常,到產生環境發現 無法找到 css 和 js

來源:互聯網
上載者:User

標籤:url   active   冰山一角   jpg   頁面   mfile   debug   call   rri   



# Production  冰山一角的悲劇啊


Started GET "/discount_service/assets/admin.js?body=1" for 127.0.0.1 at 2014-05-23 14:50:24 +0800ActionController::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 dogem ‘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



  




Rails 4.0.0 開發環境一切正常,到產生環境發現 無法找到 css 和 js

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.