Ruby on Rails Wedding Project

Milan Page
5 min readAug 20, 2021

Ok, first off wow… I did not think I was going to make it through that project. The amount of relief I have just from meeting the simple requirements is so different from the first two projects. But we’re here and we made it (now just need to take the assessment)!

If I can give one piece of advice for people working full time jobs while going to Flatiron it would be “DON’T RUSH PROJECT PLANNING!!!”. If I would’ve just swallowed my pride and taken my time in the beginning to properly plan out my project instead of just hopping right into it , especially with the Associations, this process would’ve been a whole lot easier. That being said though I was forced to learn a so much from all the tiny little bugs I had to search for.

My project is a Wedding Planning Rails Application that allows the user to create a wedding along with an associated venue. They can then view their wedding on the wedding show page or just their own personal weddings on a profile page. This Idea sparked because I had just finished wedding week for my brother and the planning building up to it was crazy. We all had to become last minute professional wedding planners.

So when I was trying to come up with an idea for this project I was still in wedding mode. I thought how cool would it be if there was an app where Wedding planners can post all the weddings they designed and then people could search through which planner they’d want to hire. Obviously this app has so much more to be done to it, but at least the backend structure and idea is there.

The application provides standard user authentication, Sign Up, Log In, along with an Omniauth Log In from Google. Once you’re logged in you have access to create, edit, and delete your own personal weddings, and to create or select an existing venue so associate your weddings with.

Models and Associations:

User:

A User has_many Weddings, and has_many Venues through weddings. The User can Sign Up if their email is unique, and can Log In if all fields are filled out correctly. On top of that they also have access to log in through Google. The user can then create and design as many weddings as they want. The weddings are displayed on their profile page and the community show page of all Weddings ever created. The user then only has access to edit and delete the weddings associated with their user_id.

Wedding:

A Wedding belongs to a user and a venue. The wedding can create venues and associate preexisting venues through a nested belongs_to form. I accomplished this by using “accepts_nested_attributes” inside of my Wedding Model.

Venue:

A Venue has_many Weddings, and has_many Users through weddings. The Venue can also create Weddings through a nested has_many form. Again this was accomplished by using “accepts_nested_attributes” inside of my Venue Model.

Forms:

Wedding Form:

To be able to create a wedding and give a Wedding the capabilities to create and select a Venue, I made a nested form using “form_for” and inside using “form_field” to allow the user to create a venue. I then used “collection_select” to let the user assign an already existing venue to their wedding if they’d like. To “build” out my venues through my wedding so the form would actually display, I used the ActiveRecord “build” method through the belongs_to side of the relationship inside my “WeddingsController”.

And of course, I had to add my “:venue_id” and “venue_attributes:[]” inside my Weddings strong params private methodwedding_params” . Or else my wedding would not be able to fully save the venue to the database.

Venue Form:

For my venue form I did the same thing, using “form_for”, and “fields_for” but did not use “collection_select”. Instead inside my “new” method in Venue Controller I instructed my venue to “build” out a form for weddings 3 times. This way the User has the option to assign multiple weddings at once to a Venue if they happened to design more than one at a time.

Now I didn’t have to add a “wedding_id” to my Venue strong params because a Venue does not belong_to a wedding, it has_many of them. So I only needed to add my “wedding_attributes:[]” inside my Venue private methodvenue_params” . Now my venue will be able to save the weddings that are assigned to them, to the database through our Active Record Relationship.

Nested Routes:

For my nested routes requirements, I nested my weddings through my venues. This way the routes go through the has_many side of the relationship so the user can view what weddings belong to each venue by clicking on a link the leads you to “venues/;id/weddings/index”, this is a “nested index route”. They can also click a link to create a new wedding associated to a specific venue through a “nested new route”, “venues/:id/weddings/new”.

How I felt starting my project without taking the time to figure out my associations completely🤦🏼‍♀️

--

--