Redirect_to and route mapper question

Hi

I have a question about route mapper and redirect_to. In routes.rb,
there are two url mappings

map.connect ‘app/person/:person_name’, :controller => ‘app’, :action
=> ‘person_profile’
map.connect ‘app/person/:person_name/book/:book_id’, :controller =>
‘app’, :action => ‘personal_reading’

In the controller, i can redirect to the first mapping using

redirect_to :action=> “person_profile”, :id=>@personal_name

But I don’t know how to redirect to the 2nd mapping. Could you please
tell me how to solve it? or tell me how to design url structure in
RoR? thanks!

–jack

jack.tang wrote:

Hi

I have a question about route mapper and redirect_to. In routes.rb,
there are two url mappings

map.connect ‘app/person/:person_name’, :controller => ‘app’, :action
=> ‘person_profile’
map.connect ‘app/person/:person_name/book/:book_id’, :controller =>
‘app’, :action => ‘personal_reading’

In the controller, i can redirect to the first mapping using

redirect_to :action=> “person_profile”, :id=>@personal_name

But I don’t know how to redirect to the 2nd mapping. Could you please
tell me how to solve it? or tell me how to design url structure in
RoR? thanks!

–jack

Try:

redirect_to :controller => ‘app’,
:action => ‘person_profile’,
:person_name => @personal name

And:

redirect_to :controller => ‘app’,
:action => ‘personal_reading’,
:person_name => @personal_name,
:book_id => @book.id

But this can be easier! Change your routes to:

map.person ‘app/person/:person_name’,
:controller => ‘app’,
:action => ‘person_profile’

map.reading ‘app/person/:person_name/book/:book_id’,
:controller => ‘app’,
:action => ‘personal_reading’

Now you can do:

redirect_to person_url(:person_name => @personal_name)
redirect_to reading_url(:person_name => @personal_name, :book_id =>
@book.id)

Aint that snazzy