0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Sinatra の使い方

Last updated at Posted at 2024-01-30

Ruby のフレームワーク Sinatra の使い方です。

ライブラリーのインストール

gem install sinatra
gem install sinatra-reloader
gem install rackup

プログラム

myapp.rb
require 'sinatra'
require 'sinatra/reloader'
 
get '/' do
    "Hello World!"
end

サーバーの起動

ruby myapp.rb -o 0.0.0.0
$ ruby myapp.rb -o 0.0.0.0
== Sinatra (v4.0.0) has taken the stage on 4567 for development with backup from Puma
Puma starting in single mode...
* Puma version: 6.4.2 (ruby 3.2.2-p53) ("The Eagle of Durango")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 11116
* Listening on http://0.0.0.0:4567
Use Ctrl-C to stop

ブラウザーでアクセス
image.png

プログラムを改造

myapp.rb
require 'sinatra'
require 'sinatra/reloader'

get '/' do
    "Hello World!<br />" +
    "Good Morning!<br />" +
    "Good Afternoon!<br />" +
    "こんにちは!<br />" 
end

ブラウザーでアクセス
image.png

確認したバージョン

$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux]

$ gem list sinatra

*** LOCAL GEMS ***

sinatra (4.0.0)
sinatra-contrib (4.0.0)
sinatra-reloader (1.0)
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?