DEV Community

Stacy Daniel
Stacy Daniel

Posted on

My Sinatra Base Web Application..."Hello Efitness!"

Getting Started: Woohoo

I must admit, This time around I wasn't as nervous and confused as I was when building my very first project here at Flatiron. I was very well prepared. I had a clear idea as to what I wanted to build and how I wanted my app to look. I decided to build a Fitness tracker Web App, in which a user/users are able to signup/login and begin tracking their workouts.

Project Structure:

Gem install Corneal

Corneal is a super convenient gem which is used for creating Sinatra base templates. The gem magically creates the file structure as well as providing useful gems in a Gemfile in other to manage the dependencies in the App.

After getting my file structure up and running, I went ahead an created my project folders and subfolders. I decided on four models: A User, Workout, Exercise and Exercise_workout. Their relationships are as follows:

class User < ActiveRecord::Base
    has_secure_password
    has_many :workouts

class Workout < ActiveRecord::Base
    belongs_to :user 
    has_many :exercise_workouts
    has_many :exercises, through: :exercise_workouts

class Exercise < ActiveRecord::Base
    has_many :exercise_workouts
    has_many :workouts, through: :exercise_workouts

class ExerciseWorkout < ActiveRecord::Base
    belongs_to :exercise
    belongs_to :workout
Enter fullscreen mode Exit fullscreen mode

Routes and Controllers

I was able to utilize RESTful routes in my App through the following:

ApplicationController is the parent controller of my App. It requires the necessary files and configures views and sessions. This controller only has one route, A Get request which renders to the homepage, along with helper methods, to check whether or not a user is logged in.

UserController has Get request which renders the user index page, signup form, as well as a Post request to create a user.

SessionsController has Get request which renders the login form, as well as a Post request to login/authenticate a user.

WorkoutController has Get requests to render the workouts index page, the form to create a new workout, as well as a Post request for that new workout created. This controller also renders the form to either update and or delete a workout.

Conclusion

This project was very rewarding and fun to work on. My biggest challenge was styling, which I ultimately decided to leave very basic. I learned how important it is to organize/have a rough idea prior to coding. I hope that the information provided will be helpful as other students like myself embark on this portion of their journey here at Flatiron. Happy coding!😁

Top comments (0)