Last active
December 18, 2015 09:19
-
-
Save jridgewell/5760666 to your computer and use it in GitHub Desktop.
Polymorphic select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Catch < ActiveRecord::Base | |
belongs_to :animal, :polymorphic => true | |
end | |
class Bird < ActiveRecord::Base | |
attr_accessible :name | |
has_one :catch, :as => :animal | |
end | |
class Fish < ActiveRecord::Base | |
attr_accessible :name | |
has_one :catch, :as => :animal, :dependent => :destroy | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select> | |
<optgroup label="Fish"><!-- That's a polymorphic class --> | |
<option value="Fish_1">Trout</option> | |
<option value="Fish_2">Salmon</option> | |
</optgroup> | |
<optgroup label="Bird"><!-- That's another polymorphic class --> | |
<option value="Bird_1">Eagle</option> | |
<option value="Bird_2">Pigeon</option> | |
</optgroup> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment