我正在用rails 3.2.8編寫一個小CMS應用程序。有段落模型(基本上包含例如新聞文章的標題,正文和日期)和頁面(包括許多段落,例如許多新聞文章)。如果日期發生變化,以下內容只會更新一個段落,否則,段落不會更新,即使例如。身體改變了!?update_attributes在某些情況下不會更新nested_attributes
page.update_attributes({"paragraphs_attributes"=>{"0"=>{"_destroy"=>"0",
"title"=>"News title", "body"=>"News text", "id"=>"4",
"date(3i)"=>"1", "date(2i)"=>"1", "date(1i)"=>"2013"}}})
下面,你可以找到模型的相關部分:
page.rb
class Page < ActiveRecord::Base
has_many :paragraphs, :dependent => :destroy
attr_accessible :name, :paragraphs_attributes
accepts_nested_attributes_for :paragraphs, :allow_destroy => true
end
paragraph.rb
class Paragraph < ActiveRecord::Base
belongs_to :page
attr_accessible :title, :body, :page, :date
validates :page, presence: true
end
是否有人有關於任何想法這種奇怪的行爲的原因?