静的ファイルの置き場所
CSSやHTMLなど静的ファイルは、public
というディレクトリに置く。
リンクは、<link rel="stylesheet" href="/style.css">
のように、パスにpublic
を含めないで書くことに注意。
├ test.rb
├ public
└── style.css
├ views
└── index.erb
public
=> 静的ファイルの置き場
views
=> テンプレートの置き場
<index.erb>
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Sinatra Practice</title> <link rel="stylesheet" href="/style.css"> </head> <body> <h1>Sinatra Practice</h1> <p>現在、<%= @now %>です。</p> </body> </html>