accepts_nested_attributes_forã«æå®ããã¢ã½ã·ã¨ã¼ã·ã§ã³ã¯è¦ªãæ´æ°ãããã¨åãæ´æ°ãã¦ããã
accepts_nested_attributes_forã£ã¦ãã©ã¼ã ãã親åã¾ã¨ãã¦ä¿åããæã«ä½¿ããã®ã¨æã£ã¦ã¾ãããããã©ã¼ã ã使ããªãã¦ã親åãã¾ã¨ãã¦ä¿åãã¦ããããã§ãããç¥ããªãã£ããä½ã¦ä¾¿å©ãªã®ã§ãããã
# ex class Diary < ActiveRecord::Base has_many :comments accepts_nested_attributes_for :comments end diary = Diary.first # å¤æ´åã®ã³ã¡ã³ãã¯ä»¥ä¸ã ã¨ãã¾ã diary.comments.first.content #=> 'å¤æ´åã®ã³ã¡ã³ã' # ã³ã¡ã³ããå¤æ´ãã¾ã diary.comments.first.content = 'å¤æ´å¾ã®ã³ã¡ã³ã' # ãã®ç¶æ ã§è¦ªãä¿åãã¾ã diary.touch # ããã¨åãä¿åãã¦ããã diary.comments.first.content #=> 'å¤æ´å¾ã®ã³ã¡ã³ã'
ä¸è¨ã®å¾ã調ã¹ãã¨ãã親åãã¾ã¨ãã¦ä¿åããéã«accepts_nested_attributes_forã使ããã«ããã£ã¨ç´ ç´ã«ã§ãããã¨ãããã£ãã
ã©ããããã¨ããã¨ã¢ã½ã·ã¨ã¼ã·ã§ã³ã®:autosaveãªãã·ã§ã³ãtrueã«è¨å®ããã
class Diary < ActiveRecord::Base has_many :comments, :autosave => true end