Other Pages

Add Pages To Create And Look At Individual Posts

Requisitos para avanzar

  • The user should be able to create a post with a title, author, date published, and content. The author should be the current user.
  • The complete post should appear on its own page (aka its show page).
  • If the user doesn't submit all required fields, they should see some error messaging, but shouldn't lose any of their work.

Create View

Show View

Elementos para discusiĆ³n

  • How do you create a resource? What parameters do you need to pass?
  • Then: what did rails make for you when you used the resource generator? Find all the new files. Maybe even list them out on a whiteboard.
  • How do you associate a user with a post?
    • What did you have to put in the migration to create posts?
    • How is this association communicated to the User and Post models?
    • How will you associate the current user with a post when you create it?
  • What's the difference between the new and create methods in the posts controller and how do these relate to the form to create a new post?

Herramientas y Referencias

Pistas

  • Rails has some built in ways to associate one model with another. See the RailsGuides link above for hints on how to make a user the owner of a post!
  • Don't hand code the form! You don't have to! Rails will help. See RailsGuide link above!
  • Rails has a built-in way to note when something was stored in the database. Probably handy for showing the date / time a post was created.
  • For now, we're going to use the user's email address when displaying a post's author. You can add names or other identifiers later! (Also, even though you're going to get the current user's email address from the User model, you'll still need a user parameter for your Post resource.)
  • You need a create method to store your post data - scroll down a little bit in this section of the Getting Started guide for very helpful information and to see an example of a create method: http://guides.rubyonrails.org/getting_started.html#creating-new-posts.

Next Step: