Guest User

Untitled

a guest
May 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #create tables
  2. create_table :people do |t|
  3. t.string :name
  4. t.timestamps
  5. end
  6.  
  7. create_table :hats do |t|
  8. t.string :type
  9. t.integer :person_id
  10. t.timestamps
  11. end
  12.  
  13. #models
  14. class Person < ActiveRecord::Base
  15. has_many :hats
  16. end
  17.  
  18. class Hat < ActiveRecord::Base
  19. belongs_to :person
  20. end
  21.  
  22. #somewhere in a controller
  23. @hat = @person.hats.new
  24. @hat.person #<==== is this possible automatically?
Add Comment
Please, Sign In to add comment