Home arrow Tricks, Tips, and Help arrow Advanced Tips arrow Rails nested attributes custom modification
Rails nested attributes custom modification Print E-mail
I have been working with an issue for a while where every time I have associations they seem to have a lot of issues going to and from XML/Params. I was impressed with nested_attributes written by Eloy Duran and packaged with Rails 2.3.2. I realized thought that there was no means of having attributes that weren't sent back up to the server deleted. I also realized there was no simple workaround this without just skipping the nested_attributes.rb altogether. I asked the main group and it seems the consent is that it is dangerous to do this, but none the less, my software needs this feature so I just copied and updated Eloy's code and created my own dangerous_nested_attributes.rb . Which is below... and here.

It should have all of Eloy's features, with the addition of an option to :destroy_missing, and I only added it to the has_many relationship.
1.) Put dangerous_nested_attributes.rb in /lib
2.) Add two lines at the bottom of config/enviornment.rb

include DangerousNestedAttributes
ActiveRecord::Base.send :include, DangerousNestedAttributes

3.) Declare it in your the model linke so

class Recommendation < ActiveRecord::Base
        has_many :recommendation_type_details, :dependent => :destroy
        has_many :recommendation_details, :through => :recommendation_type_details
        accepts_dangerous_nested_attributes_for :recommendation_type_details, :destroy_missing => true
...
end

4.) Restart your server
 
< Prev   Next >

Jibwa Work Samples

Contact Jibwa LLC

Under Construction

Jibwa.com is under construction. Watch out for broken links, missing pages, potholes and bulldozers. We apologize for the temporary inconvenience - Jibwa.com Staff

News and Updates

Flex 4 Pediatrics One

Recently Jibwa LCC published demonstration videos and a new website design for Pediatrics One Clinical Management software built on Flex Flash Builder...
Read More ...

Eclectic Flea Simple Business Site

Using hand written materials and some photos we managed to create a simple site for Tucson's artsy thrift store. The Eclectic Flea ...
Read More ...

Flash Builder 2 Release changes from beta

I am moving from (flex) Flash Builder Beta 2 to Flash Builder Release Stable and keeping notes on changes I've had to make to my code. 1.) mx names...
Read More ...

Radiology Gallery

Jibwa and Tripwirearts have built and  launched a new website with Dr Benjamin Strong. radiologygallery.com for radiology continuing medical educ...
Read More ...