DEV Community

victoriaehrbar
victoriaehrbar

Posted on

1

Sinatra Assessment

I just got a new puppy, so I was inspired to create the Pupdate Blog to create posts about my puppy's training progress. However, anyone can sign up, log in, and create their own Pupdates about their own dog.

First, I used the corneal-new gem to create boilerplate code. I added views, models, and controllers.

Users sign up using an email and password. I used the bcrypt gem to ensure the user's password is protected.

Then I set up the UsersController and PupdatesController files and mounted them in config.ru. I also added "user Rack::MethodOverride" to give access to Rack middleware so my app will have access to HTTP verbs other than GET and POST, such as PATCH and DELETE.

I created two migrations with rake db:create_migration: one for the users table and one for the pupdates table. The users table has 3 columns: name, email, password_digest. The pupdates table has a title, content, and a user_id.

Next, I created a seed file to fill the table with some dummy data to play with and test the app's functionality.

Back in the controllers, I created the routes needed for the UsersController to sign up, log in, and log out. I also added in the PupdatesController the ability to create a new post, edit a post, and delete a post. I also authenticated the user to ensure that a user can't edit or delete other users' posts. Helper methods were useful for that!

Since all of the functions are behaving well, I added some UX features. I used the flash gem to flash messages at users to give them information. For example, when you delete a post, "Pupdate deleted" appears on the screen. Users also see a flash message when they enter invalid login credentials.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay