This project is archived and is in readonly mode.

#4677 ✓invalid
Craig S Walker

attr_accessible breaks nested model attributes

Reported by Craig S Walker | May 24th, 2010 @ 12:57 AM

If a model with has_many and accepts_nested_attributes_for also has attr_accessible, then you cannot use nested model attributes to create instances of the child model in the parent model.

I confirmed this using a testbed based on the Railscast for Nested Model Forms. Survey accepts_nested_attributes_for :questions. I then run the following code:

Survey.create({:name => "test", :questions_attributes => [ { :content => "a"} ] }).questions.size

If Survey does not have attr_accessible :name, then the result of this statement is 1. If it does have it, then the result is zero.

I've tested this in Rails 2.3.2 and Rails 3, and got the same behavior.

(I originally described this on Stack Overflow)

Craig Walker

Comments and changes to this ticket

  • Kane

    Kane June 22nd, 2010 @ 06:47 PM

    RTFM ;)

    accepts_nested_attributes_for(*attr_names)

    Defines an attributes writer for the specified association(s). If you are using attr_protected or attr_accessible, then you will need to add the attribute writer to the allowed list.

    If you dont allow mass-assignment to :questions, :questions will not be assigned.

    please set to invalid.

  • Andrew White

    Andrew White June 25th, 2010 @ 05:35 PM

    • State changed from “new” to “invalid”
  • xiaobao

    xiaobao July 19th, 2010 @ 06:32 AM

    • Importance changed from “” to “Low”

    so expensive. tiffany co jewelry Why citizens pick out tiffany jewelry online shop exactly Swiss watches. It tiffany jewelry cheap is not hard to fake tiffany jewelry respond to this issue replica Links of London for sale for no one had tiffany and co ever hesitations as for tiffanys the high quality and fine jewelry refined design of Swiss tiffany jewelry outlet watches. Replica watches are replica tiffany constructor in accordance with all techniques and technical specifications of the produc

  • jim123456

    jim123456 November 8th, 2010 @ 01:21 AM

    When Coach began as Manhattan Leather Bags in 1941, they were inspired by baseball glove design and they created discount handbags with similar qualities.supra shoes didn't come along until years later. The original handbag collection had twelve designs, and they were made from supple, tan, top-quality leathers, and showed the same excellent craftsmanship and stitching that we still expect today.

    Coach hired a woman named Bonnie Cashin in 1962, and she brought new looks to Coach bags. She used many new fabrics and organic materials like jersey and wool. She created the brass hardware that is symbolic of timberland boots. When Lew Frankfort came aboard in 1979, he brought Coach to the next level, and they became a name known the world over. Affordable luxury was not a concept that many people knew, but now they would. Soon after Frankfort joined Coach, they came out with a catalog, and opened their flagship store in New York City.

    In the 1980's, Coach expanded and made innovations that brought its brand relevance and strength. They designed watches starting in 1988, and also expanded their company to Tokyo. Japan still counts among the leading purchasers of coach purses and Coach heels. The manufacture of Coach shoes began in the mid 90's, and Reed Krakoff, the lead designer, loaned his talents to help put Coach heels and louis vuitton bags outlet on the map. Their shoes aren't as popular as their handbags, but they are well worth the money invested in their purchase.

    Women love heels, but at times you may want to wear shoes that don't have this height. true religion jeans outlet are as dedicated to comfort as they are to style and pizzazz. Coach platforms come in many styles, from gold loafers to slingbacks with open toes. You may be able to find Coach shoes at discount prices online, but be sure that you are buying genuine Coach products.

    If you're looking for moncler jackets that will make you feel and look glamorous, Coach shoes and chanel purses can do that well. Coach sneakers and heels will make you feel sporty, too. When selecting pumps or sandals to wear, you'll be happy to count on the long-standing quality and service of the Coach company. They have many styles to choose from, including chic and glamorous Coach boots and Coach heels. Whether you are looking for sports shoes like Coach sneakers or sexy shoes like Coach boots, the Coach name will never let you down.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Shared Ticket Bins

Pages