Rails Review Minilab: Blog
Here's what Rails is made for! Build a straight up blog, quickly!
Part 0: Deliverables and Planning
Deliverables
Blog: your blog (or blog variant) should have users and posts. The users should be able to:
- sign up
- log in
- log out
- view posts
- create, update, and destroy only their own posts
Based on these goals, we expect everyone to complete at least part 1 of this project.
Readme: the
README.md
file inside your app should list the steps you take to complete the project, including each terminal command you run and each change you make to a file.When you're ready, use [this form] (https://docs.google.com/a/generalassemb.ly/forms/d/1zSklHtCYKg_NhkLdjlQaCXFrHJQ4Io266cKUs9_Dg8I/viewform) to let us know how the project went and to submit the link to your project on github.
Process
- Don't copy and paste or clone code. Start with
rails new -d postgresql <app name>
. - Follow Route-Side-In - start with the routes, then controllers, then templates, then models.
- Start with one part of the site's functionality. Try enabling a landing page (aka splash page) and an about page first, then move on to your more data-driven routes, controllers, and views.
- Pay attention to error messages closely - they are your best helpers!
- Work together and help each other.
Part 1: Basic Site Functionality (with Auth)
The features in part 1 of this lab would take a typical intermediate developer less than 2 hours to complete... Rails is very fast! The main reason why we want you to record the steps you take in your README.md is so that you can use it as a guide to create Rails apps quickly!
Reference the modules and readings from the last two weeks!
Things to Build
Your blog will have quite a few pieces. As you work, develop one piece of your site at a time, route-side in.
Routes & Controllers
We need routes to support our user stories, and controllers to say what should happen at those routes.
We need a site
or pages
controller with index
and about
, to show those pages on our site.
For auth, we need a users
controller with all seven routes. We also need a sessions
controller with at least new
and create
.
We need a posts
controller with all seven routes.
Views
We need views for any index
, new
, show
, and edit
routes.
Models
We need 2 models:
- a
User
model, withemail
,first_name
,last_name
, andpassword_digest
attributes- authentication (i.e.
has_secure_password
) - simple validations for a unique email, email and password confirmations, and presence for email and password attributes
- a
Post
model, withtitle
andcontent
attributes- simple validations on the title and content for presence
We need a one-to-many association: one user has many posts.
Part 2: Testing
Come up with a fun username generation scheme. Add a
generate_username
model test for youruser
, then implement yourgenerate_username
method.Add some basic
controller
tests for yoursessions
controller. Remember,new
andcreate
are the easiest actions to test in a controller.Add some basic
controller
tests for yourposts
controller. Try testing theindex
,new
,create
, andshow
actions so that the basic user workflow of creating a new post is complete.
Part 3: Layouts & Partials
Add Bootstrap to your project with the asset pipeline.
Put a basic nav bar in your
layouts/application.html.erb
.Go back through your application and separate your views into partials.
Additional Challenge Ideas
Seed your database with fake data! Add
ffaker
to your Gemfile and use it in yourdb/seeds.rb
file to create fake users and associated articles. Runrake db:seed
from the Terminal to actually seed the db.Add comments, and create a one-to-many association between posts and comments. Use nested routesto nest comments under posts. Plan out user stories and wireframe any views you'll need.
Add tags, and create a many-to-many association between tags and posts. Plan out user stories and wireframe any views you'll need.
Independent Research Ideas
Use HTTParty or a gem to consume an external API.
Upload images with Paperclip.
Use will_paginate for pagination.
Make pretty URLs with friendly-id or Stringex.
Parse words like "tomorrow" or dates like "May 27th" into specific dates, with Chronic.
Implement an "undo" functionality (e.g., to undo deleting a post) with Paranoia.
Let people donate to your blog by implementing a payment gateway with Stripe.
Submit your posts or comments through ajax.