मैंने रेल्स अनुप्रयोग में स्टाइलशीट फ़ोल्डर में फोंट के लिए एक फ़ाइल बनाई है
@font-face {
font-family: "MuseoSans500";
src: url("<%= asset_path("museosans_500-webfont.eot?")%>") format("embedded-opentype");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "MuseoSans500";
src: url("<%= asset_path("museosans_500-webfont.woff")%>") format("woff"),
url("<%= asset_path("museosans_500-webfont.ttf")%>") format("truetype"),
url("<%= asset_path("museosans_500-webfont.svg#MuseoSans500")%>") format("svg");
font-weight: normal;
font-style: normal;
}
अब जब मैं परिसंपत्तियों का चयन करता हूं .. तो यह मुझे style.css.erb पृष्ठ पर त्रुटि देता है। मैंने रास्ते के लिए sprockets पर ट्रेस रखा है और मुझे यह फ़ाइल मिली है। त्रुटि है
paths subpath /home/new_app/app/assets/stylesheets/app-theme/themes/default/style.css.erb
rake aborted!
undefined method `[]" for nil:NilClass
(in / home/hbror/applications/survey/app/assets/stylesheets/application.css)
उत्तर:
उत्तर № 1 के लिए 1आपको अपने फोंट को एक नई परिसंपत्ति निर्देशिका में रखना चाहिए, उदाहरण के लिए app/assets/fonts
और इसे अपने में रखकर संपत्ति निर्देशिकाओं में शामिल करें application.rb
:
# Add the fonts path
config.assets.paths << Rails.root.join("app", "assets", "fonts")
# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
तो फिर यह ठीक काम करना चाहिए।