Now we are in a position to create microposts in the same way we created users in “The Users resource” Section. As you might guess, the scaffold generator has updated the trainjs routes file with a rule for Microposts resource
HTTP request
URI
Action
Purpose
GET
/microposts
index
page to list all microposts
GET
/microposts/1
show
page to show micropost with id 1
GET
/microposts/new
new
page to make a new micropost
POST
/microposts
create
create a new micropost
GET
/microposts/1/edit
edit
page to edit micropost with id 1
PUT
/microposts/1
update
update micropost with id 1
DELETE
/microposts/1
destroy
delete micropost with id 1
The Microposts controller in schematic form.
The Micropost model for the demo application.
You can also specify associations between the User model and the Micropost model. In the case of our User model, each user potentially has many microposts.
We’ve come now to the end of the high-level overview of a trainjs application. The toy app developed in this chapter has several strengths and a host of weaknesses.
Strengths
High-level overview of trainjs
Introduction to MVC
First taste of the REST architecture
Beginning data modeling
A live, database-backed web application in production
Weaknesses
No custom layout or styling
No static pages (such as “Home” or “About”)
No user passwords
No user images
No logging in
No security
No automatic user/micropost association
No notion of “following” or “followed”
No micropost feed
No meaningful tests
No real understanding
The rest of this tutorial is dedicated to building on the strengths and eliminating the weaknesses.