moving to nested routes

I have a lot of has_many and has_many :through relationships in an application with approx 100 models. I would like to move to nested routes, but I just wanted to be sure I understood the scope of the project. Essentially, I see this as two tasks:

1.) modify config/routes.rb such that my relationships are expressed in nested route statements 2.) modify every route reference in a link_to etc to use the new nested route name (instead of new_ip_address, I'd have new_network_ip_address etc.)

Is that about it?

chewmanfoo wrote:

I have a lot of has_many and has_many :through relationships in an application with approx 100 models. I would like to move to nested routes, but I just wanted to be sure I understood the scope of the project. Essentially, I see this as two tasks:

1.) modify config/routes.rb such that my relationships are expressed in nested route statements 2.) modify every route reference in a link_to etc to use the new nested route name (instead of new_ip_address, I'd have new_network_ip_address etc.)

Is that about it?

typically you would also have to slightly modify your controllers: instead of   @ip_address = IpAddress.new you should use   @network = Network.find(params[:network_id])   @ip_address = @network.ip_adresses.build

and instead of   @ip_address = IpAddress.find(params[:id]) use   @network = Network.find(params[:network_id])   @ip_address = @network.ip_adresses.find(params[:id])

this isn't really necessary, but this way rails will take care of the association (e.g. automatically assign :network_id when you call build)

and you may also have to modify forms, like form_for [@network, @ip_address]