Created
January 3, 2012 03:45
-
-
Save rjfranco/1553371 to your computer and use it in GitHub Desktop.
Generating select from model
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 Character < ActiveRecord::Base | |
has_many :weapons | |
end | |
class Weapon < ActiveRecord::Base | |
belongs_to :character | |
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
/ The HAML in the view | |
= form_for(@weapon) do |f| | |
%ul.fields | |
%li | |
= f.label :character | |
= collection_select :weapon, :character_id, Character.all, :id, :name, {:prompt => 'Please Select a Character.'} |
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
undefined method `character_id' for #<Weapon:0x007f9033232088> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment