In the previous iteration, we built out our model associations and migrated our database. Now we're going to work on building useful methods (class and instance) for rendering data and our own validations. We're doing this to follow the principle that our controllers should be skinny, our models fat, so therefore our views have very little logic in them.
Before anything, note that when you generate models, controllers, etc, be sure to include this option, so that it skips tests (which we already have): --no-test-framework
There are many methods here. Check out the specs and remember to run your code in rails c
— that will help, I promise!
- The
#city_openings
method should return all of theListing
objects that are available for the entire span that is inputted. - The
.highest_ratio_res_to_listings
method should return theCity
that is "most full". What that means is it has the highest amount of reservations per listing. - The
.most_res
method should return theCity
with the most total number of reservations, no matter if they are all on one listing or otherwise.
- You'll need to write a few validations here, they are all pretty straight forward, just take a look at the tests!
- Whenever a listing is created, the user attached to that listing should be converted into a "host". This means that the user's
host
field is set totrue
- Whenever a listing is destroyed (new callback! Google it!) the user attached to that listing should be converted back to a regular user. That means setting the
host
field to false.
The same class/instance methods as your City
object. Maybe there is a way they can share code?!?!?
- Should have a
checkin
and acheckout
method. - Make sure the guest and host aren't the same user.
- Make sure any reservation that is made, doesn't conflict with others.
- Make sure the checkout time is after the check in time.
Note: Remember, if you're having trouble setting up your models' relationships, Google is your friend. There might be ways of designing associations that you haven't encountered yet but that will vastly simplify your code.
#duration
gives the duration in days#total_price
returns the price using the duration and the price per day of the listing
- Should have a description, rating and reservation
- Reviews should only be created on reservations that exist and have already happened.
View Flatiron BnB Methods Lab on Learn.co and start learning to code for free.