好的,所以编译我的资产工作正常,但是当我跑:
thin start -e production
我的javascript或css都没有加载。我的浏览器也取消了获取资产的请求。我不确定为什么会这样,但我怀疑它是因为它认为它是404'。如果您查看顶部图像,您会看到我的application.css文件已编译并存储在我的assets文件夹中,但是当我尝试访问该文件时,我收到了我的404.html文件。
给出了什么!?
修改
我被要求发表我的观点。以下是项目中的一些代码:
<% content_for :title, 'Quick Quote' %>
<% content_for :subtotal, get_subtotal %>
<% content_for :stylesheet_includes do %>
<%= stylesheet_link_tag "quote", "jquery-ui-timepicker-addon" %>
<% end %>
<% if @quote.errors.any? %>
<div class="flash alert">
<% @quote.errors.full_messages.each do |msg| %>
<div><%= msg %></div>
<% end %>
</div>
<% end %>
<h1>Quick Quote</h1>
我的布局:
<!DOCTYPE html>
<html>
<head>
<title><%= (yield(:title) + " - " unless yield(:title).blank?).to_s + "Online Scheduler Order Taker" %></title>
<%= stylesheet_link_tag "application", "jquery-ui-timepicker-addon.css", :media => "all" %>
<%= yield :stylesheet_includes %>
<%= javascript_include_tag "application" %>
<%= yield :javascript_includes %>
<%= csrf_meta_tags %>
</head>
<body>
生产中的代码.rb
config.assets.precompile += %w( quote.css jquery-ui-timepicker-addon.css prices.css contact.css )
我的application.css.scss.erb:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*
* require_tree . <- commented out
* require jquery-ui-timepicker-addon.css <- commented out
*/
我的整个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 jquery-ui
//= require jquery-ui-timepicker-addon.js
//= require_tree .
答案 0 :(得分:10)
Rails建议默认情况下禁用此设置config.serve_static_assets
,即设置为false。以下是rails app
config/environments/production.rb
中的默认配置
config.serve_static_assets = false
因此,如果您在本地应用中将其设置为true
,那么这仍然没问题。但是,如果您在Apache或ngix或heroku以外的任何其他设备上部署应用程序,则不建议在config.serve_static_assets=true
配置文件中生成production.rb
。这是Rails指南中的文档。
config.serve_static_files将Rails配置为静态服务 文件。默认为true,但在生产环境中已转为 用作运行的服务器软件(例如NGINX或Apache) 应用程序应该提供静态资产。与默认值不同 设置运行时设置为true(绝对不推荐!)或 使用WEBrick在生产模式下测试您的应用程序。否则你不会 能够使用页面缓存和对经常存在的文件的请求 无论如何,在公共目录下都会点击你的Rails应用程序。
答案 1 :(得分:6)
检查您的config/environments/production.rb
文件并添加下一行(如果还没有):
config.serve_static_assets = true
答案 2 :(得分:2)
答案 3 :(得分:1)
路轨5:
将config.public_file_server.enabled
中的production.rb
更改为true
或将具有任何值的RAILS_SERVE_STATIC_FILES
添加到env变量中。