Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rails new Test
- cd Test
- rails g scaffold hunter
- sed -i s/#.*/"has_many :animals"/ app/models/hunter.rb
- rails g scaffold animal hunter:references type:string
- sed -i s/"attr_accessible :type"/"attr_accessible :type, :id, :created_at, :updated_at"/ app/models/animal.rb
- rails g scaffold dog
- rake db:migrate
- rails console
- hunter = Hunter.create
- dog = Dog.new
- dog.hunter = Hunter.first
- dog_attributes = dog.attributes.merge(type: 'Dog')
- hunter.animals.build(dog_attributes)
- hunter.animals.first.is_a? Dog
- hunter.animals.first.is_a? Animal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement