Reputation: 3523
Small routing question:
I want
myapp.com/my_controller
-> lead to controller Amyapp.com/my_controller?uid=123
-> lead to controller Bany ideas how to change the routs file (in rails 2.3)
Upvotes: 0
Views: 1023
Reputation: 5317
Rails 2.3.1:
map.route_a 'my_controller', :controller => "A", :action => "a"
map.route_b 'my_controller/uid/:uid', :controller => "B", :action => "b"
You should get route_a_url
and route_b_url(:uid => uid)
helper method to generate urls. Its not exactly query parameters but its using uid
and a value both.
Rails 3.2.1:
match 'my_controller' => 'A#a', :as => 'route_a'
match 'my_controller/uid/:uid' => 'B#b', :as => 'route_b'
And the helper functions route_a_url
and route_b_url(:uid=>10)
were readily available.
Explnation:
In your view, use the helper functions to generate urls
Helper Function: route_a_url()
Generated URL: http://localhost:3000/my_controller
Map to: Controller A, Action a
Helper Function: route_b_url(:uid => 10))
Generated URL: http://localhost:3000/my_controller/uid/10
Map to: Controller B, Action b
Upvotes: 2