w4d2 - I got 99 problems but a Cat ain't one
If you having Rails problems I feel bad for you son…
We started building our first fully functional Rails app today. Pretty exciting! We’re starting simple by building an application called “99 Cats”, which is based on the site ‘99dresses’. I’ll forgive you if you haven’t heard of it, but it’s basically a site where users could post their used dresses for sale for some sort of virtual currency, and then turn around and use that currency to purchase dresses from other users. Apparently it was pretty successful… but it’s no longer around. Naturally, this idea also works great for Cats. The premise is slightly modified to the idea that users can post cats on the site, which are for rent, and then other users can logon and request to rent them for a period of time. Not absurd at all!
We started by putting together the basic migrations to create tables to store our Cat data. Once we had our Cat table and some database level validations, we added some additional validations to the Cat model class to prevent the ability to save any cat with incomplete information. We then worked on the individual controller actions needed to handle the different requests: viewing all cats (index), viewing individual cats (show), creating new cats (new -> create), or editing existing cats (edit -> update). We slapped together some VERY basic html pages so that we could actually see our work, which allowed us to implement some HTML staples such as tables and forms.
Once this was done we added a model for Cat Rentals, which is where we stored rental requests, along with a status of approved, denied or pending (the default). We added the required associations to the models and updated our routes for the new resource. One interesting thing that we had to figure out was that we needed to add routes for the controller to handle our “approve” and “deny” requests, which are buttons on an individual cats page (next to each potential rental request). These routes were mapped to controller actions, but the controller actions mapped back to existing pages. This was the first time that we had seen a route for a resource that didn’t have a page associated to it. I’m starting to understand now how genius Rails’ set up is, and I can see how you would easily be able to handle less concrete resources, e.g. “Likes”, in a similar manner to any of your more standard resources like pictures and comments.
Tomorrow will be Day 2 of 99 Cats, where we actually add in the user functionality, complete with sign in and authorizations. By the end of the day, we should have an application that will be pretty functional! With a little CSS styling and some investors, I think we might have a winner… We could corner the cat rental market!