LoginSignup
1
0

More than 3 years have passed since last update.

【Sinatra】立ち上げ手順

Posted at

Railsを勉強していますが、自動でやってくれることが多すぎて違和感があるので、Sinatraを勉強してみます!

立ち上げ手順

Sinatraの立ち上げ手順を示していきます。
HelloWorldを表示するところまでやっていきます。

まずは一緒に立ち上げてみましょう!

※参考
http://sinatrarb.com/intro-ja.html(日本語)
日本語版は少し古い可能性がらるようです。
http://sinatrarb.com/intro.html(英語)
せっかくなので、英語の勉強がてら、私は英語版を見て挑戦してみます。

https://qiita.com/kimioka0/items/751e460cbb59c70379c6
https://qiita.com/k-ta-yamada/items/9e35c5f8b31862267e01

Sinatraのチュートリアルに忠実に実施していきます。

フォルダとファイルの作成

適当な名前のフォルダを作成します。
フォルダを作成したら、myapp.rbというルビーのファイルを作成しましょう。

myapp.rb
# myapp.rb
require 'sinatra'

get '/' do
  'Hello world!'
end

require 'sinatra'でルーティングを呼び出しているのでしょうか。。
get '/' doで基本ページの呼び出しが出来るっぽいです。
(憶測にすぎません。)

myapp.rbの中身のコードはこんな感じです。

$ gem install sinatra

を実行してください。

Fetching: mustermann-1.0.3.gem (100%)
Successfully installed mustermann-1.0.3
Fetching: rack-protection-2.0.5.gem (100%)
Successfully installed rack-protection-2.0.5
Fetching: sinatra-2.0.5.gem (100%)
Successfully installed sinatra-2.0.5
Parsing documentation for mustermann-1.0.3
Installing ri documentation for mustermann-1.0.3
Parsing documentation for rack-protection-2.0.5
Installing ri documentation for rack-protection-2.0.5
Parsing documentation for sinatra-2.0.5
Installing ri documentation for sinatra-2.0.5
Done installing documentation for mustermann, rack-protection, sinatra after 268 seconds
3 gems installed

gemファイルが3つインストールされています。

に接続すると、HelloWorldが出てますね!

It is recommended to also run gem install thin, which Sinatra will pick up if available.

gem install thin

を実行した方が良いと書かれてます。
thinとはWebサーバのことっぽいですね。早くてお手軽のようです。

Fetching: daemons-1.3.1.gem (100%)
Successfully installed daemons-1.3.1
Fetching: eventmachine-1.2.7-x64-mingw32.gem (100%)
Successfully installed eventmachine-1.2.7-x64-mingw32
Fetching: thin-1.7.2.gem (100%)
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
Successfully installed thin-1.7.2
Parsing documentation for daemons-1.3.1
Installing ri documentation for daemons-1.3.1
Parsing documentation for eventmachine-1.2.7-x64-mingw32
Installing ri documentation for eventmachine-1.2.7-x64-mingw32
Parsing documentation for thin-1.7.2
Installing ri documentation for thin-1.7.2
Done installing documentation for daemons, eventmachine, thin after 11 seconds
3 gems installed

インストール出来ました!

まとめ

HelloWorldを表示させるだけっだたので簡単でしたね。
次回はルーティングを見ていきます!

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