Skip to content

Instantly share code, notes, and snippets.

@tacettin
Created December 26, 2013 13:26
Show Gist options
  • Save tacettin/8133819 to your computer and use it in GitHub Desktop.
Save tacettin/8133819 to your computer and use it in GitHub Desktop.
First of all in has_many class name should be in plural: has_many :choices And you should add attr_accessible poll_id or choice_ids for Model from which you want to edit this association. Or just delete all attr_accessible for first try.
class Poll < ActiveRecord::Base
attr_accessible :published, :title, choice_ids
validates :published, :presence => true
validates :title, :presence => true, :length => { :minimum => 10 }
has_many :choices, :dependent => :destroy
end
class Choice < ActiveRecord::Base
belongs_to :poll
attr_accessible :choice_text, :votes, :poll_id
validates :choice_text, :presence => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment