For tonight's lab, we'd like you to create a Blog app where a user can create a post, see all posts and see an individual post. The user should also be able to assign tags to each post and for every post they should be able to create a tag, view all tags, and view all posts by tags.
- Each post should have a title, description and author
- Each tag should have a name
- Remember that many posts can have many tags, and many tags can belong to multiple posts
- Generate your models and migrations and begin to model your relationships (remember this is a many to many relationship that you should model using has_many through)
- Run your migrations and make sure you have the correct foreign key setup
- For each model, make sure everything is working in
rails console
before you start building your routes, controllers and views (create a post, create a tag, see what posts belong to a certain tag etc.) - Once you have tested your models in Rails console, create the routes required to create and show data with your models.
- Setup a route, make a controller method, and the associated view for a
post
. - Continue this for the resource until you've implemented your index, new, create and show actions for
post
. - Then go back and add the ability to add a
tag
with your newpost
- Finally make a
TagsController
#index
should show all tags#show
should show you thetitle
andauthor
of everypost
associated with thattag
.- each
post
on the show page should include a link to the associatedpost
. Use RESTful practices for this link and you should be fine.
- each
- Setup a route, make a controller method, and the associated view for a
If you get stuck with the first two steps, look at the notes from this morning and try those examples to help solidify the routing and CRUD concepts. Once you are past step 3, look back at the notes from this afternoon to help you with routing, your controllers and views.
-
Add routes and methods to update an exiting post and destroy a post.
-
Try to include your own styling, bootstrap or another CSS framework in your application and style your blog.