在Heroku中不加载CSS [英] CSS not loading in Heroku
问题描述
我将我的应用程序部署到了Heroku,但只有资产\\ images正在加载。 CSS文件(尤其是包含90%CSS的custom.css文件)未被加载。我在本地预编译了这些资产,并没有运气将它们推到Heroku。只有图像加载,而不是custom.css文件。
我注意到Heroku日志中有一个有趣的错误:
开始GET/users/css/parallax-slider.css为77.777.777.77于2013-06-13 02:42:09 +0000
2013-06-13T02:42:09.016864 + 00 :00 app [web.1]:ActionController :: RoutingError(No route matches [GET]/users/css/parallax-slider.css):
它正在寻找我的用户控制器文件夹中的CSS?这是为什么应用程序无法加载custom.css文件?
production.rb
App :: Application.configure do
#此处指定的设置优先于config / application.rb中的设置
#代码不会在请求之间重新加载$ b $ b config.cache_classes = true
#完全错误报告被禁用并且缓存打开
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
#禁用Rails的静态资产服务器(Apache或nginx已经这样做)
config.serve_static_assets = false
#压缩JavaScript和CSS
config.assets.compress = false
#如果预编译的资源不存在,则不要回退到资产管道
config.assets.compile = false
#为资产URL生成摘要
config.assets.digest = true
#默认为零并保存在由config.ass指定的位置ets.prefix
#config.assets.manifest = YOUR_PATH
#指定您的服务器用于发送文件的标头
#config.action_dispatch.x_sendfile_header =X-Sendfile #for apache
#config.action_dispatch.x_sendfile_header ='X-Accel-Redirect'#for nginx
#强制所有通过SSL访问应用程序,使用Strict-Transport-Security,以及使用安全的cookie。
#config.force_ssl = true
#查看日志中的所有内容(默认为:info)
#config.log_level =:debug
#使用以下标记预先安排所有日志行
#config.log_tags = [:subdomain,:uuid]
#为分布式设置使用不同的记录器
#config.logger = ActiveSupport :: TaggedLogging.new(SyslogLogger.new)
#在产品中使用不同的缓存存储
#config.cache_store =:mem_cache_store
#启用图像服务,样式表和来自资产服务器的JavaScript
#config.action_controller.asset_host =http://assets.example.com
#预编译附加资产(application.js,application。 css,所有非JS / CSS都已添加)
config.assets.precompile + =%w(custom.css hover.css users.css works.css styleie9.css)
#禁用投递错误,错误的电子邮件地址将被忽略
#config.action_mailer.raise_delivery_errors = false
#启用线程模式
#config.threadsafe!
#启用I18n的语言环境回退(查找任何语言环境回落到
#无法找到翻译时的I18n.default_locale)
config.i18n.fallbacks = true
#将弃用声明发送给已注册的侦听器
config.active_support.deprecation =:notify
#将查询计划记录为超过此值(工程
#with SQLite,MySQL和PostgreSQL)
#config.active_record.auto_explain_threshold_in_seconds = 0.5
#TODO:编辑设计邮件配置
config.action_mailer.default_url_options = { :host => 'localhost:3000'}
end
application.rb
需要File.expand_path('../ boot',__FILE__)
#选择你想要的框架:
需要active_record / railtie
需要action_controller / railtie
需要action_mailer / railtie
需要active_resource / railtie
需要sprockets / railtie
#需要rails / test_unit / railtie
如果已定义(Bundler)
#如果您在部署到生产之前预编译资产,请使用以下命令:
Bundler.require(* Rails .groups(:assets =>%w(开发测试)))
#如果你想让你的资产在生产中被懒惰地编译,使用这行
Bundler.require(:default,:assets,Rails .env)
结束
模块应用程序
类应用程序< Rails :: Application
#config / environments / *中的设置优先于这里指定的设置。
#应用程序配置应该放入config / initializers中的文件
# - 该目录中的所有.rb文件都会自动加载。
#自定义包含要自动加载的类和模块的目录。
#config.autoload_paths + =%W(#{config.root} / extras)
#按照给定的顺序(默认是按字母顺序)加载这里命名的插件。
#:所有可用作未明确命名的所有插件的占位符。
#config.plugins = [:exception_notification,:ssl_requirement,:all]
#激活应该始终运行的观察者。
#config.active_record.observers =:cacher,:garbage_collector,:forum_observer
#将Time.zone默认设置为指定区域,并将Active Record自动转换为该区域。
#运行rake -D time获取查找时区名称的任务列表。默认是UTC。
#config.time_zone ='中央时间(美国和加拿大)'
#默认语言环境是:en,并且所有来自config / locales / *。rb,yml的翻译都是自动加载的。
#config.i18n.load_path + = Dir [Rails.root.join('my','locales','*。{rb,yml}')。to_s]
#config.i18n。 default_locale =:de
#配置Ruby 1.9模板中使用的默认编码。
config.encoding =utf-8
#配置将从日志文件中过滤的敏感参数。
config.filter_parameters + = [:password]
#在JSON中启用转义HTML。
config.active_support.escape_html_entities_in_json = true
#在创建数据库时,使用SQL而不是Active Record的模式转储程序。
#如果您的模式不能被模式自卸器完全转储,则
#就像您有约束或数据库特定的列类型一样
#config.active_record.schema_format =: sql
#强制执行批量分配的白名单模式。
#这将为您的应用中的所有模型
#创建一个可用于批量分配的空白白名单。因此,您的模型需要使用attr_accessible或attr_protected声明将可访问的
#参数明确列入白名单或黑名单。
config.active_record.whitelist_attributes = true
#启用资产管道
config.assets.enabled = true
#您的资产版本,更改如果你想过期所有的资产
config.assets.version ='1.0'
#需要Heroku部署
config.assets.initialize_on_precompile = false
#get预编译在heroku上工作:
#config.assets.initialize_on_precompile = true
config.serve_static_assets = false
#为Bootstrap主题添加字体
config.assets.paths<< Rails.root.join(app,assets,fonts)
#防止密码写入日志
config.filter_parameters + = [:password,:password_confirmation]
end
end
任何帮助将不胜感激。我已经度过了两个不眠之夜,我完全陷入了沉思。
谢谢!
-b
编辑1
application.css:
/ *
*这是一个清单文件,将被编译到application.css中,该文件将包含所有文件
*下面。
*
*此目录下的任何CSS和SCSS文件,lib / assets / stylesheets,vendor / assets / stylesheets,
*或者vendor / assets / stylesheets的插件这里使用相对路径引用。
*
*您可以自由地将应用程序范围的样式添加到此文件中,并且它们将出现在
*编译文件的顶部,但创建新文件通常会更好每个样式范围。
*
* = require_self
* = require_tree。
* /
.pagination {
background:white;
cursor:default;
margin-top:20px;
a,span,em {
padding:0.2em 0.5em;
display:block;
float:left;
margin-right:1px;
路线:
认证:用户做
root:to => 'activities#index'
end
root:to => home#index
devise_for:users,:controllers => {:registrations => 注册}
资源:用户做
成员做
获得:跟随,:追随者,:帖子,:评论,:活动
结束
结束
资源:作品做
资源:评论
结束
资源:关系,仅:[:create,:destroy]
资源:posts
资源:activities
资源:转发
资源:注释做
成员做
放:toggle_is_contribution
结束$ b $结束
资源:探索
结束
请更改 config.serve_static_assets = true
在您的 production.rb
请让我知道发生了什么.hope它会工作..
谢谢
I deployed my app to Heroku but only the assets\images are loading. The CSS files (especially the one that contains 90% of the CSS, custom.css) are not being loaded. I precompiled the assets locally and pushed them to Heroku with no luck. Only the images are loading, not the custom.css file.
I did notice an interesting error in the Heroku log:
Started GET "/users/css/parallax-slider.css" for 77.777.777.77 at 2013-06-13 02:42:09 +0000 2013-06-13T02:42:09.016864+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/users/css/parallax-slider.css"):
why is it looking for the css in my users controller folder? Is this why the app can't load the custom.css file?
production.rb
App::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = false
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w(custom.css hover.css users.css works.css styleie9.css)
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
#TODO: Edit devise mailer config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
#Bundler.require(:default, :assets, Rails.env)
end
module App
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
#Required for Heroku deployment
config.assets.initialize_on_precompile = false
#get precompilation working on heroku:
#config.assets.initialize_on_precompile = true
config.serve_static_assets = false
#Add fonts for Bootstrap theme
config.assets.paths << Rails.root.join("app", "assets", "fonts")
#Prevent passwords from being written to logs
config.filter_parameters += [:password, :password_confirmation]
end
end
Any help would be greatly appreciated. I've spent two sleepless nights on this and I am completely stumped.
Thanks! -b
EDIT 1
application.css:
/*
* 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 .
*/
.pagination {
background: white;
cursor: default;
margin-top: 20px;
a, span, em {
padding: 0.2em 0.5em;
display: block;
float: left;
margin-right: 1px;
}
Routes:
authenticated :user do
root :to => 'activities#index'
end
root :to => "home#index"
devise_for :users, :controllers => { :registrations => "registrations" }
resources :users do
member do
get :following, :followers, :posts, :comments, :activities
end
end
resources :works do
resources :comments
end
resources :relationships, only: [:create, :destroy]
resources :posts
resources :activities
resources :reposts
resources :comments do
member do
put :toggle_is_contribution
end
end
resources :explore
end
Please make this changes config.serve_static_assets = true
in your production.rb
Please let me know what happen.hope it will work..
Thanks
这篇关于在Heroku中不加载CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!