Betelhem Elfagid
4 min readMar 5, 2021

--

My Sinatra Project

I have just completed Active Record and Sinatra Module and I am so excited and looking forward to start the next phase.

This project definitely has more functionalities and a bit complex than the first CLI project however I have gained a better understanding, I believe I am improving throughout the leaning process and I hope I will gain much more understanding and knowledge from my next module, Rails which I am so looking forward to learn all about it.

It Is absolutely amazing to work on the back and front end using model, view, controller and see fully functioning app.

My first step for the project was to come up with an idea, our instructor was repeatedly mentioning to us to start thinking about project ideas way before project week, which I regrate not doing so and I completely understand him now! setting up a clear idea of what you want to do is definitely a huge step and it helps throughout the project!

My app is called preserve our planet, the idea came up from my family member and after watching sir David Attenborough’s documentary, it is an amazing idea and can be broaden however as this is my first project I want to start simple, the app tracks what people/users have done daily to preserve our planet, it could be recycling, planting or organized with communities to clean up their areas, anything that can help to protect the environment, it is just a simple app to spread awareness of climate change.

A user can sign up for an account by providing a username, password, and email, once they sign up and log in, they are then able to create, read, edit, delete their actions.

The next step was making a simple diagram for my model’s relationship which I believe make things clearer.

Using Corneal gem was a time saver, it uploads all the file structures for my MVC app including the layout which later I alter and added gems as my liking, the next step I have done was setting up my database migrations and creating tables and seed file and working on associations followed by my project models which is the ‘logic’ of the web application where data is manipulated and/or saved, the controller goes hand in hand with models and view, it relays data from the browser to the application, and from the application to the browser. and views are where we find html, css, javascripts , it is the front-end and user-facing part of a web application and inheritance of the model and controllers.

I have set up config.ru to run only one controller, the application controller, all other controllers are simply preceded by the word ‘use’, config.ru file includes Rack::MethodOverride so that you are able to use this middleware for patching and deleting, doing so I was keep getting error Sinatra doesn’t know this ditty, my edit page couldn’t load and I was frustrated, I needed to move around Rack::MethodOverride and try and finally I moved it inside my application-controller and that’s where it worked for me.

The App full fills the project requirement of CRUD functionality, it can create, read, update, delete user’s actions and only users who has logged in can do delete and update their actions as I included validations and the helper method.

As we know there are plenty of websites that require us to register and we intend to register with the same or similar username and passwords over and over again and think about how that make hacking easier for hackers, Thankfully we do have ‘bcrypt’, it is a hashing algorithm used to store passwords securely. It is implemented in Ruby via the bcrypt gem I have included in my project the has_secure_password macro and password_digest which works together in bcrypt as both need to be present for it to work.

I also integrate carrierwave to my app in order to load images, this gem is designed to allow users of your website to upload files such as photos/images, It works well with Rack based web applications, such as Ruby on Rails, after adding carrierwave in my gem, I created a ruby file called image uploader in my model and the class ImageUploader inherits from CarrierWave::Uploader::Base.

In the process of developing my app I was executing shotgun gem multiple times in order to test my progress locally in the browser using default localhost:9393.

And finally, I managed to do a little css designing to make my app approachable, I have tried to incorporate bootstrap and manual css styling and even if I kept the styling simple, it definitely takes most of my time, perhaps that’s because I love to see things pretty.

Happy codding and stay safe everyone!

--

--

Betelhem Elfagid
0 Followers

Full stack software engineering graduate from Flatiron School.