2013-10-13 50 views
7

我在生產中沒有摘要的情況下提供的字體資產出現問題。 只要我做耙資產:預編譯,我得到:在Ruby on Rails中沒有摘要的字體資源4

5futurebit-webfont-c133dbefd9e1ca208741ed53c7396062.eot 

我試圖把它與字體面與資產URL,資產路徑,字體鏈接和字體路徑,但所有SCSS鏈接他們的最終輸出路徑:

/assets/5futurebit-webfont.eot 

現在我從/應用程序/資產/字體複製資產直奔/公/資產/但它並不認爲這是個做到這一點的方式。

+1

我相信這個問題可能是相關http://stackoverflow.com/questions/10905905/using-fonts-with-rails-asset-pipeline –

回答

0

請確保您有在您的字體的URL聲明,如字體的extention名確切的文件名:

正確:

@font-face{ 
    font-family: 'Sawasdee'; 
    src: font-url('Sawasdee.ttf') format('truetype'); 
} 

錯誤:

@font-face{ 
    font-family: 'Sewasdee'; 
    src: font-url('Sewasdee') format('truetype'); 
} 

我的字體文件夾:

fonts 
|_ Sewasdee.ttf 
|_ Otherfont.ttf 
2

我一直在尋找類似的問題,目前正在使用非愚蠢的摘要資產寶石:https://github.com/alexspeller/non-stupid-digest-assets

有關如何使用它的更多信息,請參見此處。 Correct use of non-stupid-digest-assets gem

現在說的是,Chris提供的鏈接(具體來說,https://stackoverflow.com/a/17367264/291640)似乎可以完成與沒有gem本身的gem相同的鏈接。我知道我需要進一步研究。

+0

+1非愚蠢消化資產寶石。 Rails應該有這樣的選擇。 –

0

這是我們的解決方案,部分基於Sprocets的功能。它正在與Rails4合作。預編譯完成後,它會自動爲所有資產生成一個非摘要版本,這些資產在config.assets.precompile中列出。

# lib/tasks/assets_nondigest.rake 
require 'fileutils' 

namespace "assets:precompile" do 
    desc "Create nondigest versions of defined assets" 
    task :nondigest => :environment do 
    sprocket_task = Sprockets::Rails::Task.new ::Rails.application 
    assets = ::Rails.application.config.assets.precompile 

    paths = sprocket_task.index.each_logical_path(assets).to_a + 
     assets.select { |asset| Pathname.new(asset).absolute? if asset.is_a?(String)} 

    paths.each do |path| 
     if asset = sprocket_task.index.find_asset(path) 
     copy_target = File.join(sprocket_task.output, asset.digest_path) 
     target = File.join(sprocket_task.output, asset.logical_path) 

     sprocket_task.logger.info "Writing #{target}" 
     asset.write_to target 
     asset.write_to "#{target}.gz" if asset.is_a?(Sprockets::BundledAsset) 
     end 
    end 
    end 
end 

Rake::Task['assets:precompile'].enhance do 
    Rake::Task['assets:precompile:nondigest'].invoke 
end