Don't forget to use Git to save your projects!
In these projects, you'll finally really get to dive into ActiveRecord's associations, one of the best features it offers. The tutorial chapter will have you creating microposts for your users and the other project will give you a chance to add some more interesting associations to your previous work.
Lay out the data architecture you'd need to implement to build the following scenarios:
This chapter of the tutorial begins the conceptual heavy lifting. For beginners trying to plough through the tutorial, this is usually the beginning of the "I'm doing it but not understanding it" phase. Luckily, you've already learned everything that will be covered in the tutorial and this should be a great chance to see it in action as part of a real website.
The basic gist of it is that, to have a microposting site like Twitter, you've got to actually have microposts. Users create microposts, so you can surely expect that a User will
has_many microposts. With the association done, the rest is really just about setting up the correct views to display the microposts.
As with the previous chapter, just make sure you're writing the test specs in the correct files and stick with it. There's a lot of ground to cover but, again, the conceptual hurdles should be well within reach at this point.
You want to build a site similar to a private Eventbrite which allows users to create events and then manage user signups. Users can create events and send invitations and parties (sound familiar?). Events take place at a specific date and at a location (which you can just store as a string, like "Andy's House").
A user can create events. A user can attend many events. An event can be attended by many users. This will require you to model many-to-many relationships and also to be very conscious about your foreign keys and class names (hint: you won't be able to just rely on Rails' defaults like you have before).
We've gotten quite far here, so these tasks will only lay out the high level overview of what you're meant to build. You'll need to implement the details yourself. As usual, it's not meant to look pretty, just work. Design is all extra credit.
#showactions. You'll need to make a form where you can sign up a new user and a simple
#showpage. You should be getting better and faster at this type of vanilla controller/form/view building.
sessionhash or the
cookieshash and retrieve it when necessary. It may be helpful to always display the name of the "signed in" user at the top.
#createaction should use the
#buildmethod of the association to create the new event with the user's ID prepopulated. You could easily also just use Event's
::newmethod and manually enter the ID but... don't.
@upcoming_events = current_user.upcoming_eventsand
@prev_events = current_user.previous_events. You'll get some practice with working with dates as well as building some queries.
Send us your solution so we can show others! Submit a link to the Github repo with your files in it here using any of the methods listed on the contributing page. Please include your partner's github handle somewhere in the description if they would like attribution.
This section contains helpful links to other content. It isn't required, so consider it supplemental for if you need to dive deeper into something
From the creators of The Odin Project...