My Sinatra project is an online book review application in which a user can create, view, edit and delete their book review posts after safely signing up or logging in to their accounts. The user can also view others' posts, but he/she may not be allowed to edit or delete other users' posts. Here is my live site: https://sinatra-book-app.herokuapp.com/
Through this project, I have gained a better understanding of the MVC pattern, which I believe is the core concept of building up a Sinatra project.
The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components: the model, the view, and the controller. Each of these components are built to handle specific development aspects of an application. The model contains the logic of the application. The view implements the interface of the application. The controller is a linker between the model and the view.
The best practice is that the model and the view should NEVER communicate. All of the views should get their information from controllers.
Furthermore, I have solidified my knowledge of user authentication. Below are the basic steps to create a user authentication in the Sinatra project:
(1) Add bcrypt
to the gemfile, which would provide a hashing algorithm to the userโs password.
(2) Add has_secure_password
to the User model.
(3) The user table must have a password_digest
column in the database where the salted and hashed password will be stored.
(4) When a user has successfully authenticated themselves, store their user.id
in the session as below:
session[:user_id] = user.id
(5) Ensure that the attribute we find users by login is unique.
In short, building up a Sinatra project from scratch on one's own is challenging; but once you've gone through the whole process, researched and corrected every single error, and finally push your site online, you would find how rewarding your hard work is!
Top comments (0)