在我的路线中,我定义了一个带有一些ID的全局类别来加载动态内容:
get "/:global_category/:id" => "pages#index"
该路线位于routes.rb的底部。 一切都很简单,没有问题,至少在开发方面。 现在我还通过CSS将一些webfonts加载到我的应用程序中,当我'在生产中,每当我的字体加载时,我都会收到以下异常:
undefined method `id' for nil:NilClass
受影响的网址是: http://www.example.com/assets/Sansation_Bold-webfont.woff
我在/ sass文件中加载位于/ assets / fonts中的字体,如下所示:
@font-face
font-family: 'ApolloASM'
src: url('ApolloASM-webfont.eot')
src: url('ApolloASM-webfont.eot?#iefix') format('embedded-opentype'), url('ApolloASM-webfont.woff2') format('woff2'),url('ApolloASM-webfont.woff') format('woff'),url('ApolloASM-webfont.ttf') format('truetype'),url('ApolloASM-webfont.svg#apollo_asmregular') format('svg')
font-weight: normal
font-style: normal
我的路线和资产管道显然存在冲突。 仅在制作时(我部署在 heroku )我可以重现这一点,所以我尝试修改我的production.rb但是在查看了文档(http://guides.rubyonrails.org/asset_pipeline.html)之后我仍然不是真的知道该怎么做。
我也尝试过预编译资产。
这似乎不是问题的原因,而且我的字体都正确加载! 任何提示都表示赞赏。
答案 0 :(得分:0)
这样的路由的问题是它将与系统上的其他路径的负载相匹配。例如," / users / 123"将被解释为pages#index params={:global_category => "users", :id => 123}
,而您可能期望它转到users#show params={:id => 123}
。
答案 1 :(得分:0)
我使用sass帮助程序“font-url”解决了它:
@font-face
font-family: 'ApolloASM'
src: font-url('ApolloASM-webfont.eot')
src: font-url('ApolloASM-webfont.eot?#iefix') format('embedded-opentype'), font-url('ApolloASM-webfont.woff2') format('woff2'),font-url('ApolloASM-webfont.woff') format('woff'),font-url('ApolloASM-webfont.ttf') format('truetype'),font-url('ApolloASM-webfont.svg#apollo_asmregular') format('svg')
font-weight: normal
font-style: normal
无需在production.rb或application.rb文件中预编译或添加任何内容
确保字体全部存储在/ app / assets / fonts目录中。