Skip to content

Instantly share code, notes, and snippets.

@bobbywilson0
Created October 2, 2014 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bobbywilson0/75c5e822077a684b9e0b to your computer and use it in GitHub Desktop.
Save bobbywilson0/75c5e822077a684b9e0b to your computer and use it in GitHub Desktop.
Put a bird on it.
class CreateBirds < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :location
t.belongs_to :birdable, polymorphic: true
t.timestamps
end
end
end
class Bag < ActiveRecord::Base
def put_a_bird_on(location)
birds.create(location: location)
end
end
class Bird < ActiveRecord::Base
belongs_to :birdable, polymorphic: true
end
bag = Bag.new
bag.put_a_bird_on("it")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment