Ruby On Rails Portfolio Project

Rony M.
4 min readSep 15, 2021

For my third Flatiron project I have built a Rails-based E-commerce prototype.

Right after creating the Rails environment and the initial structure by simply running the “rails new” command, I have installed my first gems, which are Devise (for authentication, including Google and GitHub OAuth) along with simple_form and bootstrap with font-awesome for styling. Some custom CSS was also added, mostly for the logo and the footer.

Moving on from (O)Auth and styling, I’ve created some initial routing for navigation testing through the MVC pattern, defining my index.html.erb in the “home” folder as my root route, which only contains my logo partial.

The first model, controller, view and migration created are related to the courses, which included CRUD functionalities.

Next up, the second MVC was created for users, for which I have also installed the Rolify gem, so the created users would have limited action permissions depending on their roles. for Both the Course and Users models from this point can relate to each other. On this case, the Course class “belongs_to :user” and the User class “ has_many :courses”.

For my Users’ controller, I have set up a method which sets the first created user as an “:admin” by default, while it also have the permission to change its own role(s):

While creating a new course, its form offers inputs such as course description, number of lessons (more about that soon), language and difficulty level, other than displaying on its show layout the date of creation and the username of its creators:

Along with that, I have added a search functionality for created courses and pagination if needed, using the Ransack and Pagy gems:

Next step was adding lessons table to the courses through migration, creating their new relationships. CRUD included:

Couldn’t miss the enrollments to the courses, right? They are provided as well. Again, a migration and MVC were needed and also new model relationships, them being:

But, right before the users get enrolled to a course, a payment option is required, unless the course is set to < 0 (free course, on this case).

For that, I’ve added the Stripe API for real payments to be displayed, if the course price is above 0. That’s when I’ve added the first helper method inside a CoursesHelper module:

The enrollment button then gets rendered inside the “_course” partial. When getting enrolled to a paid course, we may then consume the Stripe API and input some fake data for testing:

And finally, when the user is enrolled to a course, it may also add a review to it with a score and a comment, allowing it to edit it as well:

This is it! At least for now. I may eventually add more features to it and update its front end, maybe by turning into a SPA through a JS library and turn it into an actual e-commerce website.

Till next project!

--

--