Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 KB | None | 0 0
  1.     rails new Test
  2.  
  3.     cd Test
  4.  
  5.     rails g scaffold hunter
  6.     sed -i s/#.*/"has_many :animals"/ app/models/hunter.rb
  7.     rails g scaffold animal hunter:references type:string
  8.     sed -i s/"attr_accessible :type"/"attr_accessible :type, :id, :created_at, :updated_at"/ app/models/animal.rb
  9.     rails g scaffold dog
  10.  
  11.     rake db:migrate
  12.  
  13.     rails console
  14.  
  15.     hunter = Hunter.create
  16.     dog = Dog.new
  17.     dog.hunter = Hunter.first
  18.     dog_attributes = dog.attributes.merge(type: 'Dog')
  19.     hunter.animals.build(dog_attributes)
  20.  
  21.     hunter.animals.first.is_a? Dog
  22.     hunter.animals.first.is_a? Animal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement