DEV Community

abnercabrera28
abnercabrera28

Posted on

Ruby on Rails Project

The third month has passed which means it was once again project week, this time using ruby on rails. This month was especially hard for me to focus on the labs and lectures, mainly because of mental exhaustion. Everything I tried to learn seemed so complex to understand so I was very concerned when it came to planning for my project. In theory, it was very simple: I was just going to make an extension of my previous wrestling Sinatra project. But applying all the new things I learned turned out to be challenging.

I set up my models which were user, wrestler, and team, with wrestlers being the join table. I added the necessary code for each of their controllers. Up to this point, everything was fairly simple. The problem came when I was setting up my forms for the wrestlers new page. Wrestlers have five attributes: name, where they're from, birthdate, belts, and special moves. So I was surprised when I hit the submit button and saw an error that said "Team must exist."

In my models, teams have many wrestlers and wrestlers belong to teams, but teams weren't meant to be an attribute to create a new wrestler. I spent maybe three hours trying to fix this error with a couple of people until I did eventually figure out the solution the next morning. I ended up making a nested form with an option for a user to create a new team for that wrestler, or to select from an existing team. I had to add team_attributes to my wrestlers_params method in my wrestlers controller for it to all work out.

Top comments (0)