small medium large xlarge

Generic-user-small
19 Sep 2008, 09:38
Jakub Żurkowski (2 posts)

in restful2/app/controllers/comments_controller.rb listed in pages 434/5 in action “create” (and “update” also) we don’t save the parent after doing « operation (or update_attributes in “update”). Probably it’s just a typo, because page 341 states that you need to save the parent of has_many relationship explicitly after that « operation in order to write it into database. Please dispel my doubts.

Samr_small_pragsmall
19 Sep 2008, 16:03
Sam Ruby (634 posts)

implicit save. I just verified this using the debugger. I don’t see this mentioned in the “Rails documentation”:http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html

Generic-user-small
20 Sep 2008, 17:27
Jakub Żurkowski (2 posts)

hmm… that’s strange - if « saves the relation into database, then why is this used (p.449): * @article.comments « comment if @article.save flash[:note] = “Thank you for your valuable comment” end*

instead of

if(@article.comments « comment) end

which I see in my very first example from page 435?

this code seems to save article twice (or at least once a new comment and once an @article) or not at all.

(firstly I thought it makes second @article.save to be always true, but I rethought it and now I guess that it would also be nil)

You must be logged in to comment