ActiveRecordã®ã‚¢ã‚½ã‚·ã‚¨ãƒ¼ã‚·ãƒ§ãƒ³ã‚’扱ã†ãƒ¡ã‚½ãƒƒãƒ‰ã§ã€Œbuildã€ã¨ã„ã†ã®ã‚’åˆã‚ã¦çŸ¥ã‚Šã¾ã—ãŸã€‚ class Group < ActiveRecord::Base has_many :users end class User < ActiveRecord::Base belongs_to :group end ã¨ã„ã†ã‚¢ã‚½ã‚·ã‚¨ãƒ¼ã‚·ãƒ§ãƒ³ãŒã‚ã£ãŸã¨ãã«ã€ @group.users.build params ã¿ãŸã„ãªæ„Ÿã˜ã§æ›¸ãã“ã¨ãŒã§ãã¾ã™ã€‚ @group.users << userã¿ãŸã„ãªã‚³ãƒ¼ãƒ‰ã¯ save ã¾ã§å®Ÿè¡Œã•ã‚Œã¦ã—ã¾ã†ã®ã§ã€å ´åˆã«ã‚ˆã£ã¦ã¯ build ã®æ–¹ãŒã„ã„ã‹ã¨ã€‚ belongs_to ã«ã¤ã„ã¦ã® build ãªã‚‰ @user.group.build params ã ã‘ã˜ã‚ƒãªã㦠@user.build_group params ã¨ã„ã†æ›¸ã方もã§ãるよã†ã§ã™ã€‚ å‚考: Rail
{{#tags}}- {{label}}
{{/tags}}