rubyonrailsin

A Ruby and Rails talk

Sunday, March 14, 2010


Re: [Rails] validates_presence_of :parent_id stopping save

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi,


I'm not sure 100% what you're trying to do but the presence of question_id will not be there until the record has been saved. No?

And I'm not sure why you're doing this .... @grading = @question.gradings.build(more_attributes)

Shouldn't you have done a build before presenting your form if you have nested forms?

Maybe you could teach me something on what you're trying to do.

On 13 March 2010 16:54, Max Williams <lists@ruby-forum.com> wrote:
Hi. I'm using rails 2.3.4 and have this association between two of my
models.

Question
 has_many :gradings

Grading
 belongs_to :question

Grading has this validation:
 validates_presence_of :question_id

And this validation test is stopping me from doingg this, which i would
normally expect to work

@question = Question.new(attributes)
@grading = @question.gradings.build(more_attributes)
@question.save #fails because grading has no question_id

Now, i thought that this would work ok because (in my understanding) the
question is saved and then it saves it's built associated objects.  How
can i ensure this will work?  Do i need to drop the validation?  I'd
rather not if possible.

Grateful for any advice - max
--
Posted via http://www.ruby-forum.com/.

--
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.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--
100% naturally selected. 0% designed.

--
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.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive