Redirect to parent?

2 views
Skip to first unread message

Kevin Fullerton

unread,
Feb 20, 2008, 5:52:44 AM2/20/08
to resource_...@googlegroups.com
Hi,

Just started using resource_controller with a project, and I have a question about how to redirect to the parent in a polymorphic nested controller.

My routes.rb looks like

map.resources :customers, :has_many => :addresses

My customers controller is

class CustomersController < ApplicationController
resource_controller
end

And addresses controller is

class AddressesController < ApplicationController
resource_controller
belongs_to :customer
end

In a Customer view if I add <%= link_to 'New Address', new_customer_address_url(@customer) %> I get sent to the new Address screen - I can insert the
new record completely but I then want to redirect to the /customers/:id/show url instead of /customers/:id/addresses/:1 - is this possible with a
polymorphic controller - in the future I'll want /contacts/:id/show when I enter a new address using /contacts/:id/addresses/new

Many thanks

Kevin Fullerton

James Golick

unread,
Feb 20, 2008, 7:33:54 AM2/20/08
to resource_...@googlegroups.com
Try create.wants.html { redirect_to smart_url(parent_url_options) }

That should do it.
Reply all
Reply to author
Forward
0 new messages