Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #create tables
- create_table :people do |t|
- t.string :name
- t.timestamps
- end
- create_table :hats do |t|
- t.string :type
- t.integer :person_id
- t.timestamps
- end
- #models
- class Person < ActiveRecord::Base
- has_many :hats
- end
- class Hat < ActiveRecord::Base
- belongs_to :person
- end
- #somewhere in a controller
- @hat = @person.hats.new
- @hat.person #<==== is this possible automatically?
Add Comment
Please, Sign In to add comment