Jomazon Prime — Ruby on Rails

The journey through Flatiron School’s Software Engineering Bootcamp Program continues with the introduction of Ruby on Rails - an incredible framework that streamlines the software development process one thousand percent. As a way to test out the new tools and knowledge that we’ve been given, I decided to model my Rails project after the online shopping website Amazon. My app is called Jomazon Prime (no copyright infringement intended, Mr. Bezos!)

Models & Associations

Rails Generators

rails g resource User

This single line of code generates the following files for us:

create    db/migrate/20210124223541_create_users.rbcreate    app/models/user.rbcreate    app/controllers/users_controller.rbcreate    app/views/userscreate    app/assets/stylesheets/users.scss

It also primes our config/routes.rb file with MVC routes that we can use to navigate through our application. We’ll want to repeat this command for each of our models, fix our migration files to build our database, then edit each model class to reflect the associations we’ve previously decided for them. And just like that, we’ve got ourselves the foundation of our new application — whew!

Routes & Controllers

Example usage of a Sessions Controller

With the login system in place, we can start filling in the rest of our controllers, always keeping in mind our RESTful routes. The views are directly affected by how we define the actions in their corresponding controllers, so I like to edit these files simultaneously. We want to keep as little logic in our views as possible, so any queries to the database (like finding a User or a Product) should be done either in the controllers (or in some cases the model itself) and saved to an instance variable, which you can then use in your view. It definitely took some practice for me to really get comfortable with this style of programming, but it was and continues to be incredibly rewarding once I finally got a good grasp on it.

Buyers & Sellers

User class defining different associations

Rails Form Generators

Example usage of ‘form_for’ to generate a form for a New Product

As you can see, this form uses different HTML elements, including text_field, text_area, number_field, collection_select, hidden_field, and file_field. If you inspect the page in the browser, you’ll notice that Rails has intelligently transformed all of these into valid HTML DOM elements.

Custom Routes

Rails Custom Routing

Conclusion

Jomazon Prime ~ Ruby on Rails

Software Engineer | React | Redux | Ruby | Rails

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store