Skip to content

Commit 5929459

Browse files
fix(tutos): sinatra
1 parent 2e6e43f commit 5929459

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

tutorials/sinatra/index.mdx

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ tags: ansible Sinatra Ruby RubyGems
99
categories:
1010
- instances
1111
dates:
12-
validation: 2024-10-29
12+
validation: 2025-05-14
1313
posted: 2018-08-17
1414
---
1515

1616
Sinatra is a lightweight domain-specific programming language and web application library that is used for writing web applications.
1717

1818
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+
1920
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).
2021

2122
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
3132

3233
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.
3334

34-
35-
```
35+
1. Update the APT package cache.
36+
```
3637
apt update
3738
```
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.
3940
```
4041
apt install gnupg2 nodejs curl ruby
4142
```
42-
2. Import the signing key to be able to verify the RVM packages downloaded in the later step.
43+
3. Import the signing key to be able to verify the RVM packages downloaded in the later step.
4344
```
4445
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
4546
```
46-
3. Install Ruby Version Manager along with a stable Ruby version.
47+
4. Install Ruby Version Manager along with a stable Ruby version.
4748
```
4849
\curl -sSL https://get.rvm.io | bash -s stable
4950
```
50-
4. Update your shell environment to be able to access Ruby.
51+
5. Update your shell environment to be able to access Ruby.
5152
```
5253
source /usr/local/rvm/scripts/rvm
5354
```
54-
5. Confirm that Ruby is installed.
55+
6. Confirm that Ruby is installed.
5556
```
5657
ruby -v
57-
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]
5858
```
5959

6060
## Installing Sinatra
6161

62-
Install Sinatra just as any other gem
62+
Install Sinatra as a gem.
6363

6464
```
6565
gem install sinatra
66-
```
67-
68-
which returns
69-
70-
```
71-
Successfully installed sinatra-4.0.0
72-
Parsing documentation for sinatra-4.0.0
73-
Done installing documentation for sinatra after 1 seconds
74-
1 gem installed
66+
gem install rackup puma
7567
```
7668

7769
## Creating your first Sinatra Application
7870

7971
1. Create a new file that you can call `testapp.rb`.
8072
```
81-
nano testapp.rbna
73+
nano testapp.rb
8274
```
8375
2. Paste the following:
8476
```
@@ -91,6 +83,7 @@ Done installing documentation for sinatra after 1 seconds
9183
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.
9284
```
9385
ruby testapp.rb -o 0.0.0.0
86+
9487
[2023-03-27 16:36:07] INFO WEBrick 1.4.4
9588
[2023-03-27 16:36:07] INFO ruby 2.6.10 (2022-04-12)
9689
== 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
119112
"Welcome to the index. It will help you find the information you need"
120113
end
121114
```
122-
2. Run your little app.
115+
2. Run your app.
123116
```
124117
ruby testapp.rb -o 0.0.0.0
125118
```
@@ -144,8 +137,8 @@ Taking the same example as above, we will play a little more with the index. In
144137

145138
```
146139
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"},
149142
{title: 'France Gall, Poupée de cire poupée de son', url: "https://www.youtube.com/watch?v=rRva0YOVtcI"},
150143
]
151144
erb :default
@@ -174,7 +167,7 @@ The last line redirects to an ERB file which automatically looks for a file call
174167
<title>Famous French Chansons</title>
175168
</head>
176169
<body>
177-
<h1>A list of the most loved chansons ever</h1>
170+
<h1>A list of the most loved French chansons ever</h1>
178171
<% @songs.each do |song| %>
179172
<h3> <%= song[:title] %></h3>
180173
<p> <a href="<%=song[:url]%>"> Video </a></p>

0 commit comments

Comments
 (0)