LoginSignup
9

More than 5 years have passed since last update.

Sinatraでerbを使う

Last updated at Posted at 2015-07-19

はじめに

http://qiita.com/ms2sato/items/7c07b2079b48c49fad2a の続き

とりあえず何か動かせたので、もう少しちゃんとしていく。

erbを使う

erbファイルの作成

前回作ったsinatformのディレクトリの中に、viewsというディレクトリを作成して、index.erbというファイルを作成します。中身は下記のような感じで。

<html>
<head>
  <meta charset="UTF-8">
</head>
<body>
こんにちは。HTMLで書きました。
</body>
</html>

app.rb の修正

app.rb を下記のように修正します。

require 'sinatra'
require 'sinatra/reloader'

get '/' do
  erb :index # :indexの部分はviewsの下に作ったファイル名に合わせる
end

これで、 http://localhost:4567 をリロード!
「こんにちは。HTMLで書きました。」と表示されていたらOKです!

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9