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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---