Skip to content

Instantly share code, notes, and snippets.

@rjfranco
Created January 3, 2012 03:45
Show Gist options
  • Save rjfranco/1553371 to your computer and use it in GitHub Desktop.
Save rjfranco/1553371 to your computer and use it in GitHub Desktop.
Generating select from model
class Character < ActiveRecord::Base
has_many :weapons
end
class Weapon < ActiveRecord::Base
belongs_to :character
end
/ 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.'}
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