Home arrow Tricks, Tips, and Help arrow Code and Documentation for Programmers 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

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 ...

Spark List Vscrollbar on Left side

I spend an unusual amount of time trying to figure out how to set up scrollbars in spark flex (flash builder) beta 2. I wanted a list with the scrollb...
Read More ...

Flex/Flash Builder Params Base

I looked around for a while today at support forums to find out how to include params.base by default in my flash builder flex 4, and flex 3 applicati...
Read More ...

TripwireArts Website

Jibwa LLC partner TripwireArts has a newly designed website with information on some of our clients and established services....
Read More ...