Forms and Views

Tour of the sample code

  • Reference containing all the code: Forms View Demo Code
  • Feel free to look, but DON’T COPY/PASTE! I trust you otherwise why would I give you the repo?
  • Take 10 minutes now to grab the code from github and look around
Models
  • There are 4 models
    • Item (Has many comments)
    • Category (Has many items)
    • Comment (Belongs to a comment)
Routes
  • Discussion: URLs, HTTP verbs and routes
    • What’s a good URL to see all items?
    • What’s a good URL for search?
    • What’s a good URL for seeing a list of comments? Think again
    • What’s a good URL for creating a comment?
    • Let’s look at routes.rb and take turns explaining each line
Rake Tips
  • rake db:migrate:reset
  • rake db:seed
Let’s look: Migrations
  • Nothing special going on
  • Notice exactlhy ONE per table (at this stage of the game)
Let’s look: Bootstrap
  • Bootstrap is an open source front-end framework
  • It came from Twitter, and used to be caleld “Twitter Bootstrap” but now it is its own open source project, and is called just “Bootstrap”
  • It consists solely of css, javascript, some images, and some fonts
Look at code for Bootstrap
  • Look at Bootstrap
  • Look at Bootstrap Demo Github
  • Not using any gems for now!!
  • Why is most of the Bootstrap setup in application.html.erb?
  • Where else do we see bootstrap?
Partials
  • the _form.html.erb is a partial (view)
  • the same body of the form is used in a new and update scenario
  • Incorporate with render 'partial'
Seed data
  • Put enough ‘real looking’ seed data so you can get a feel for the UI
  • seeds.rb is a regular ruby program. Look at sample code.

Hacking the sample

  • Get formdemo to run on your computer
  • Update the new item form so it looks as pretty as the search form
  • Update the new item form so it shows a popup of categories instead of a blank