Skip to content
Dave Strus edited this page Nov 13, 2014 · 2 revisions

Note model

Lab: Note model

Create a Note model.

A note should have the following fields:

  • title
  • body_html (type text)
  • body_text (type text)
  • user_id, with an index
  • timestamp fields

Create a model, complete with database table, for Note. When you are finished, you should be able to do the following from the console:

[1] pry(main)> ironman = User.create username: 'tstark', password: 'iamhandsome', password_confirmation: 'iamhandsome'
[2] pry(main)> note = Note.new title: "Groceries", body_text: "Cookies and ice cream", body_html: "<ul><li>Cookies</li><li>ice cream</li></ul>"
[3] pry(main)> note.user = ironman
[4] pry(main)> note.save
[5] pry(main)> ironman.notes

If everything is set up correctly, the last statement should return something like this:

=> [#<Note id: 1, title: "Groceries", body_html: "<ul><li>Cookies</li><li>ice cream</li></ul>", body_text: "Cookies and ice cream", user_id: 1, created_at: "2014-11-09 20:06:58", updated_at: "2014-11-09 20:06:58">]