Ruby on Rails Wednesday, December 19, 2012



On Tuesday, 18 December 2012 23:30:57 UTC-5, dekhaus wrote:


For reference = here is the ruby code for the Survey and Question classes ...

class Survey < ActiveRecord::Base

 has_many :questions, :dependent => :destroy

 accepts_nested_attributes_for :questions, :allow_destroy => true,

                               :reject_if => lambda {|attrs| attrs['text'].blank? }

 attr_accessible :name, :description

end

[snip]
 

I get this error when I run the test.rb script (see code snippet above) ...

/Users/dse/.rvm/gems/ruby-1.9.3-p327@sq/gems/activerecord-3.2.9/lib/active_record/associations/association.rb:204:in `raise_on_type_mismatch': Question(#70357035179920) expected, got Hash(#70357017137920) (ActiveRecord::AssociationTypeMismatch)


accepts_nested_attributes creates a writer method on Survey, but it's not 'questions' (which is the association) but rather 'questions_attributes'.

--Matt Jones

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/sJU0WqSc4nEJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment