我想從Rails public/
目錄提供一個生成的靜態網站(包含文檔)。我的目錄結構是這樣的:Rails:不允許訪問靜態資產目錄沒有結尾/
`-- rails-root
| [...]
|-- public
| |-- assets
| | |-- favicon.png
| | |-- fonts
| | | `-- ...
| | |-- images
| | | `-- ...
| | |-- javascripts
| | | `-- ...
| | `-- stylesheets
| | `-- ...
| |-- documentation
| | |-- GLOSSARY.html
| | |-- index.html
| | `-- ...
我複製我生成的文件rails-root/public/documentation
,一切都很好,只要我要求它http://<site>/documentation/
或http://<site>/documentation/index.html
。
但是,當我要求http://<site>/documentation
導軌試圖有幫助,並提供我的index.html
頁面。頁面中的所有鏈接都是相對的,所以從不同的基礎(根目錄)而不是目錄(documentation/
)提供的鏈接使其無法加載任何資產,看起來不合適,並且無法從所有鏈接導航。
我試圖建立一個路由進行重定向,以防有人請求http://<site>/documentation
(不帶後綴斜線):
get '/documentation', :to => redirect('/documentation/index.html')
這是不行的,我猜是因爲public
文件優先在路由?我也嘗試一個僞造的路徑只是爲了驗證我的路由代碼是正確的,它的工作:
get '/xxx', :to => redirect('/documentation/index.html')
我想無論是防止鐵軌被幫助的(我很好用404 http://<site>/documentation
只要尾隨/ works; 404比一個破損的頁面更好)或重定向。我正在使用Rails 4.2。任何想法歡迎!