Quickly setting up a MVC Sinatra project

Hualiang Tian
2 min readJun 15, 2021

After completing the Sinatra project, these are the small small tips that helped me quickly build a minimum viable project. I hope these tips can help people have an easier time completing their second project.

#Planning stage

*Tip #1, Brainstorm about your models and their relationship. (belongs_to, has_many, has_many: -blank-, through: -blank-)

*Tip #2, Determine your data type and column content for your data base table.

Tip #3 Make sure you have all the update to gem before running the “bundle install”

Gems and version used for mine project

In the event that you encounter version errors like me, an easy fix is to copy and paste the gem files from your most recent labs. Since the project is simply an extension of what we learned, gem files and gem versions from our latest labs should contain all the files we need to complete the project.

  • *Tip #4. Add in the “use Rack::MethodOverride” in your config.ru file or your edit forms & pathways will not work!!!
  • *Tip #5. Create some seed data so you will some visual data to work with, especially if you are a visual learner.
  • *Tip #6. Within your models, make sure to include the macro for “has_secure_password” and “validates.” For instance, you will want to verify that all the field within the form you created are completed before the user can mover forward.
Some examples of the things that can be validated
  • *Tip #7. Make sure you “enable sessions” in your ApplicationController, and “set :session _secret, ‘anything here’ ”!!! Otherwise, you app will have security loop holes and not be able to verify the identity of the account/user.
  • *Tip #8. Make sure you put the helper methods in the ApplicationController, this way all your other sub-controllers will have access to them once it is inherited from the Application controller.
Helper methods for the main ApplicationController
  • *Tip #9. Make sure that there is a security measure in place for all the pathways that involves editing/deleting method so only the authorized user with the correct session id can modify their own content.

--

--