jjzjj

AutoSave

全部标签

ruby-on-rails - has_many autosave_associated_records_for_*

我正在尝试关联现有记录,同时仍然能够添加新记录。以下不起作用,但非常接近我需要的。如何完成关联现有记录和创建新记录?has_many:comments,:through=>:commentings,:source=>:commentable,:source_type=>"Comment"accepts_nested_attributes_for:comments,:allow_destroy=>truedefautosave_associated_records_for_commentscomments.eachdo|comment|ifexisting_comment=Comment

ruby-on-rails - rails 协会 :autosave doesn't seem to working as expected

我做了一个真正的基础github项目here这说明了这个问题。基本上,当我创建一个新评论时,它会按预期保存;当我更新现有评论时,它不会被保存。然而,这不是:autosave=>true的文档所说的……他们说的恰恰相反。这是代码:classPosttrue,:inverse_of=>:post,:dependent=>:destroydefcomment=(val)obj=comments.find_or_initialize_by(:posted_at=>Date.today)obj.text=valendendclassComment:commentsend现在在控制台中,我测试:p
12