繁体   English   中英

资产预编译好,但尝试获取文件时为404

[英]Asset Precompilation OK, but 404 when trying to get files

好的,所以编译我的资产工作正常,但当我运行时:

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>

我的production.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 .

Rails建议默认情况下应禁用此设置config.serve_static_assets ,即设置为false。 以下是rails app中生成的config/environments/production.rb的默认配置

禁用Rails的静态资产服务器(Apache或nginx已经这样做了)

config.serve_static_assets = false

因此,如果您在本地应用程序中将其设置为true ,那么这仍然很好。 但是,如果您在Apache或ngix或heroku以外的任何其他设备上部署应用程序,则不建议在您的production.rb配置文件中production.rb config.serve_static_assets=true 这是Rails指南中的文档。

config.serve_static_files配置Rails本身以提供静态文件。 默认为true,但在生产环境中关闭,因为用于运行应用程序的服务器软件(例如NGINX或Apache)应该为静态资产提供服务。 与默认设置不同,在运行时(绝对不推荐!)或使用WEBrick在生产模式下测试应用程序时将此设置为true。 否则,您将无法使用页面缓存,并且对公共目录下经常存在的文件的请求将无论如何都会打到您的Rails应用程序。

URL - http://guides.rubyonrails.org/configuring.html

检查你的config/environments/production.rb文件并添加下一行(如果它还没有):

config.serve_static_assets = true

你能把这一行放在你当前的环境中吗.rb?

config.serve_static_assets=true

参考: 这里

Rails 5:

更改config.public_file_server.enabledproduction.rbtrue或添加RAILS_SERVE_STATIC_FILES任意值针对Env变量。

参考: https//github.com/rails/rails/pull/18100

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM