图标没有在heroku中显示,但它们是本地的

时间:2014-12-18 18:43:56

标签: ruby-on-rails ruby heroku

application.rb中

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Gcp
  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.

    # 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
    # Heroku requires this to be false
    config.assets.initialize_on_precompile = false
  end
end

我在推送到heroku之前做了预编译

@font-face {
  font-family: "moon";
  src: url("fonts/icomoon.eot");
  src: url("fonts/icomoon.eot?#iefix") format("embedded-opentype"), url("fonts/icomoon.svg#moon") format("svg"), url("fonts/icomoon.woff") format("woff"), url("fonts/icomoon.ttf") format("truetype");
  font-weight: normal;
  font-style: normal; }

但是当我启动网站时,它并没有给我任何图标。

https://myapp.herokuapp.com/assets/slide4.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) https://myapp.herokuapp.com/assets/img/timer.png
Failed to load resource: the server responded with a status of 404 (Not Found) https://myapp.herokuapp.com/assets/img/loader.gif
Failed to load resource: the server responded with a status of 404 (Not Found) https://myapp.herokuapp.com/assets/img/large_right.png
Failed to load resource: the server responded with a status of 404 (Not Found) https://myapp.herokuapp.com/assets/img/large_left.png
Failed to load resource: the server responded with a status of 404 (Not Found) https://myapp.herokuapp.com/assets/fonts/icomoon.woff
Failed to load resource: the server responded with a status of 404 (Not Found) https://myapp.herokuapp.com/assets/fonts/icomoon.ttf
GET https://myapp.herokuapp.com/assets/bootstrap.css.map 404 (Not Found) /assets/bootstrap.css.map:1

我还需要做什么,以便在推送到heroku后显示图标。

我修复了css thingy没有显示,但现在它似乎没有找到正确的道路。

https://myapp.herokuapp.com/assets/fonts/icomoon.woff他们不在https://myapp.herokuapp.com/assets/home/fonts/icomoon.woff等。

在本地,图标正常运行。

我的宝石文件

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

gem 'better_errors'
gem 'slim'
gem 'heroku'
group :production do
  gem 'rails_12factor'
end

我还需要改变什么:(

2 个答案:

答案 0 :(得分:5)

试试这个,无论您的CSS文件是什么,使用字体定义,使其成为.scss文件,并使用帮助程序来获取正确的路径:

@font-face {
  font-family: "moon";
  src: font-url("icomoon.eot");
  src: font-url("icomoon.eot?#iefix") format("embedded-opentype"), 
       font-url("icomoon.svg#moon")   format("svg"), 
       font-url("icomoon.woff")       format("woff"), 
       font-url("icomoon.ttf")        format("truetype");
  font-weight: normal;
  font-style: normal;
}

注意我还从路径中删除了fonts/font-url帮助程序负责处理,我假设字体位于app/assets/fonts目录中。这也假设您正在使用sass-rails(这会提供助手)。

答案 1 :(得分:2)

我一直有这个问题,因为font-face的路径不正确,你必须玩它才能确保但它应该像

@font-face {
  font-family: "moon";
  src: url("/assets/home/fonts/icomoon.eot");
  src: url("/assets/home/fonts/icomoon.eot?#iefix") format("embedded-opentype"), url("/assets/home/fonts/icomoon.svg#moon") format("svg"), url("/assets/home/fonts/icomoon.woff") format("woff"), url("/assets/home/fonts/icomoon.ttf") format("truetype");
  font-weight: normal;
  font-style: normal; }

看到我在强文

前添加了'/ assets /'