[英]Sinatra with Slim template--cannot link to css file: What is the path from a template file to a css file in the public directory?
[英]How to link a css file with the Slim templating engine?
我正在做一個Sinatra / Slim小項目,我想包含一個CSS文件。 除此之外一切正常。
這是我的項目“樹”:
├── essai.rb
└── views
├── form.slim
└── style.css
這是form.slim的負責人:
html
head
title Vote
link href="style.css" rel='stylesheet' type='text/css'
我已經嘗試過"views/style.css"
, "../style.css"
"views/style.css"
"../style.css"
,...等。 但是Rake記錄錯誤"GET /style.css HTTP/1.1" 404
。 我知道我沒有在Sinatra中使用CSS的路線,但是我想有個避免這種情況的技巧...我希望:D
我試着在苗條的示例頁面上看到: file_path("style.css")
但是,我有一個undefined method 'file_path'
錯誤,我想是因為它的紅寶石函數在苗條的示例中傳入了args。
有人可以告訴我該怎么做嗎? 謝謝!
Sinatra希望您的css文件文件位於public
目錄中,而不是默認位於views
目錄中。
因此,您的項目樹應看起來像這樣。
/essai.rb
/views
/form.slim
/public
/css
/style.css
然后,您應該可以使用現有的苗條模板訪問它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.