You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sinatra is a lightweight domain-specific programming language and web application library that is used for writing web applications.
17
17
18
18
It provides a faster and simpler alternative to Ruby frameworks such as Ruby on Rails. Sinatra is written in [Ruby](https://www.ruby-lang.org/en/) and the code for Sinatra applications will be written in Ruby too.
19
+
19
20
Sinatra routes browser requests to code that can handle those requests. Then it will render templates back to the browser as a response. For more information on Sinatra, refer to the [official documentation](http://sinatrarb.com/documentation.html).
20
21
21
22
To use Sinatra, we need to install three pieces of software: Ruby, RubyGems, and Sinatra. Sinatra depends on Ruby and RubyGems.
@@ -31,54 +32,45 @@ To use Sinatra, we need to install three pieces of software: Ruby, RubyGems, and
31
32
32
33
The easiest way to install Ruby and RubyGems is using the Ruby Version Manager (RVM). RVM allows you to have multiple Rubies, with their own sets of gems (gemsets), installed.
33
34
34
-
35
-
```
35
+
1. Update the APT package cache.
36
+
```
36
37
apt update
37
38
```
38
-
1. (Optional) Install `nodejs`, `gunpg2`, `ruby`, and `curl`. When using Rails, you must install Node.js, in any version you want. The asset pipeline compiler of Rails requires a JavaScript runtime. If you do not use Rails, skip this and proceed to the next step.
39
+
2. Install `nodejs`, `gunpg2`, `ruby`, and `curl`. When using Rails, you must install Node.js, in any version you want. The asset pipeline compiler of Rails requires a JavaScript runtime. If you do not use Rails, skip this and proceed to the next step.
Done installing documentation for sinatra after 1 seconds
74
-
1 gem installed
66
+
gem install rackup puma
75
67
```
76
68
77
69
## Creating your first Sinatra Application
78
70
79
71
1. Create a new file that you can call `testapp.rb`.
80
72
```
81
-
nano testapp.rbna
73
+
nano testapp.rb
82
74
```
83
75
2. Paste the following:
84
76
```
@@ -91,6 +83,7 @@ Done installing documentation for sinatra after 1 seconds
91
83
3. Run your Sinatra application. The `-o 0.0.0.0` parameter will bind the application to all interfaces of the server. Without this parameter, it will only be accessible from your localhost.
92
84
```
93
85
ruby testapp.rb -o 0.0.0.0
86
+
94
87
[2023-03-27 16:36:07] INFO WEBrick 1.4.4
95
88
[2023-03-27 16:36:07] INFO ruby 2.6.10 (2022-04-12)
96
89
== Sinatra (v3.0.4) has taken the stage on 4567 for development with backup from WEBrick
@@ -119,7 +112,7 @@ In the example above, The `get '/' do` part of the code is very important. It sa
119
112
"Welcome to the index. It will help you find the information you need"
120
113
end
121
114
```
122
-
2. Run your little app.
115
+
2. Run your app.
123
116
```
124
117
ruby testapp.rb -o 0.0.0.0
125
118
```
@@ -144,8 +137,8 @@ Taking the same example as above, we will play a little more with the index. In
144
137
145
138
```
146
139
get '/index' do
147
-
@songs = [{title: 'Charles Trenet, Le mer', url: "https://www.youtube.com/watch?v=qEkd1qWonj8"},
148
-
{title: 'Edith Piaf, Non je ne regrette rien', url: "https://www.youtube.com/watch?v=t6wjCcWC2aE"},
140
+
@songs = [{title: 'Charles Trenet, La mer', url: "https://www.youtube.com/watch?v=qEkd1qWonj8"},
141
+
{title: 'Edith Piaf, Non, je ne regrette rien', url: "https://www.youtube.com/watch?v=t6wjCcWC2aE"},
149
142
{title: 'France Gall, Poupée de cire poupée de son', url: "https://www.youtube.com/watch?v=rRva0YOVtcI"},
150
143
]
151
144
erb :default
@@ -174,7 +167,7 @@ The last line redirects to an ERB file which automatically looks for a file call
174
167
<title>Famous French Chansons</title>
175
168
</head>
176
169
<body>
177
-
<h1>A list of the most loved chansons ever</h1>
170
+
<h1>A list of the most loved French chansons ever</h1>
0 commit comments