[Rails] Re: validates_presence_of :parent_id stopping save

2010-03-16 Thread Max Williams
paul h wrote: > Hi Max, > > Have you tried: > > @question = Question.create(attributes) > @grading = @question.gradings.build(more_attrs) > > Using create instead of new will save the Object to the DB first, and > hence: > Hi Paul. Yes, i know that, thanks - in this situation i would do grad

[Rails] Re: validates_presence_of :parent_id stopping save

2010-03-15 Thread paul h
Hi Max, Have you tried: @question = Question.create(attributes) @grading = @question.gradings.build(more_attrs) Using create instead of new will save the Object to the DB first, and hence: @question[:id] will/should/may not be nil when building your gradings. I'm six months in to Rails, don't

Re: [Rails] Re: validates_presence_of :parent_id stopping save

2010-03-15 Thread Anthony Gardner
I don't have your original mail and am not sure of the model but question_id is a foreign key.No? You are checking for the existence of it before it has been created, that is why it's failing, no? validate methods validate the data before its saved. Unless I'm missing something from your original

[Rails] Re: validates_presence_of :parent_id stopping save

2010-03-14 Thread Max Williams
Hi Anthony, thanks. I'm not using the rails-supplied nested attributes methods here, though maybe i should. I'm effectively hand-rolling my own, so i create a question and some associated objects (eg a grading in this case) at the same time, from a single form. When i drop the validation on

[Rails] Re: validates_presence_of :parent_id stopping save

2010-03-14 Thread Max Williams
Rob Lacey wrote: > I'd say the best way to deal with this is never validate for a > association_id > > #validates_presence_of :question_id > validates_presence_of :question > > would be better. Hi Rob! I played with this already, and got a surprising result: >>@question = Question.new(attribu