没有使用 Capistrano 和 Rails 生成图像和字体
No images and fonts production using Capistrano and Rails
在我的本地服务器上一切正常,但在生产环境 (EC2 Amazon) 中,我的一些(但不是全部)字体和图像无法加载。
这是application.rb:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_model/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require 'carrierwave'
require 'carrierwave/orm/activerecord'
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module TestApp
class Application < Rails::Application
#adding fonts to assets pipeline
config.assets.paths << Rails.root.join("app", "assets", "fonts")
# 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.
config.autoload_paths << Rails.root.join('lib')
# 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 = :ru
config.serve_static_files = true
config.serve_static_assets = true
config.assets.compile = true
end
end
很多时候资产会在开发中加载,但一旦投入生产,这取决于您如何 linking 到资产,links 可能会中断。确保您使用的是 Rails 到 link 提供的资产 link 助手。
示例:
常规浏览量:
<%= image_tag "rails.png" %>
您可以使用 sass-helpers 来引用样式表中的字体和图像,例如:
src: font-url(...)
image-url("rails.png") /** becomes url(/assets/rails.png) **/
image-path("rails.png") /** becomes "/assets/rails.png". **/
如果您不使用 SASS,您可以将 css 更改为 css.erb,然后执行以下操作:
.class { background-image: url(<%= asset_path 'image.png' %>) }
更多资产 link 示例:http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
在我的本地服务器上一切正常,但在生产环境 (EC2 Amazon) 中,我的一些(但不是全部)字体和图像无法加载。
这是application.rb:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_model/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require 'carrierwave'
require 'carrierwave/orm/activerecord'
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module TestApp
class Application < Rails::Application
#adding fonts to assets pipeline
config.assets.paths << Rails.root.join("app", "assets", "fonts")
# 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.
config.autoload_paths << Rails.root.join('lib')
# 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 = :ru
config.serve_static_files = true
config.serve_static_assets = true
config.assets.compile = true
end
end
很多时候资产会在开发中加载,但一旦投入生产,这取决于您如何 linking 到资产,links 可能会中断。确保您使用的是 Rails 到 link 提供的资产 link 助手。
示例:
常规浏览量:
<%= image_tag "rails.png" %>
您可以使用 sass-helpers 来引用样式表中的字体和图像,例如:
src: font-url(...)
image-url("rails.png") /** becomes url(/assets/rails.png) **/
image-path("rails.png") /** becomes "/assets/rails.png". **/
如果您不使用 SASS,您可以将 css 更改为 css.erb,然后执行以下操作:
.class { background-image: url(<%= asset_path 'image.png' %>) }
更多资产 link 示例:http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets