I am currently using nested model mass assignment on one of my models. It works a treat, however, I'd like to be able to ensure that any nested models that are created "belong_to" the same user.
I've managed to implement this by using alias method chaining with:
def contact_attributes_with_user_id=(attributes)
self.contact_attributes_without_user_id = attributes.merge( "user_id" => user_id )
end
alias_method_chain :contact_attributes=, :user_id
Now this works fine, but it means I can no longer have attribute protection on user_id for the contact - which could easily catch someone out in the future.
Can anyone come up with a better way?