Sinatra is the second-most popular web framework written in Ruby (after Rails). It's much simpler than Rails, and it's a great way to try out web development.
What you'll learn
- Sinatra
- HTTP Requests
- ERB Templates
Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.
Sinatra is the second-most popular web framework written in Ruby (after Rails). It's much simpler than Rails, and it's a great way to try out web development.
Sinatra is a simple web framework. We'll discuss exactly what that means, and how Sinatra can help you build web apps. Then we'll install Sinatra, and try out a simple app.
Chevron 7 steps1:16
7:25
6 questions
5:44
7 questions
3 objectives
2:41
Sinatra has a feature that makes it easy to load text in from files: ERB templates. ERB stands for "Embedded Ruby". It allows you to take a text file, such as an HTML template, that always shows the same static text, and embed Ruby code into it, that displays changing dynamic data.
Chevron 12 steps2:39
2 objectives
2:19
1 objective
2:43
4:19
1 objective
7:15
1 objective
4:22
3 objectives
5 questions
Our users can view pages that we've created for them. But a major feature of a wiki is the ability for users to create their own pages, and they can't do that yet. So let's fix that. Our next task is to set up a form so that users can create their own pages.
Chevron 10 steps3:20
3:58
1 objective
5:18
3 objectives
4 questions
3:38
8:47
4 objectives
6 questions
In this stage, we'll need to set up another pair of new Sinatra routes. The first route will accept GET requests and return an HTML form for a wiki page, just like before. The difference is that this HTML form will be pre-populated with an existing page's content. The second route will accept the completed form data, also just like before. But since we're updating existing data on the server, we need to send a PUT request, not a POST request.
Chevron 5 steps7:32
4 objectives
6:43
6 objectives
5 questions
We can add new wiki pages, show pages we've added, and then update them. The only thing missing now is the ability to delete pages. Let's add that now. We'll also show you how to serve a static CSS file to make your site look more appealing. Finally, we'll link to that CSS file from every page on our site using a Sinatra layout.
Chevron 8 steps5:17
6 objectives
3:30
1 objective
5:12
1 objective
6 questions
1:10
Jay McGavren
Get personalized course recommendations, track subjects and courses with reminders, and more.