rails 3, can I create a route that includes a url param?
we have
match '/m/:id' => 'foo#mobilemethod'
mobilemethod accepts a url param ?find=true
that puts it in 'find mode'
is there a way to add a route /f/:id
开发者_Go百科 that will call mobilemethod with the url param ?find=true
(or, is there a way for a method to know WHICH route was originally invoked, in which case I could simply map both /m and /f to the same method then inside the method check which one was invoked on the url)
I tried
match '/f/:id' => 'foo#mobilemethod?find=true'
and
match '/f/:id' => 'foo#mobilemethod/:id?find=true'
but get 'unknown action' errors
This should do this trick:
match '/f/:id' => 'foo#mobilemethod', :defaults => {:find => true}
match '/f/:id' => 'foo#mobilemethod'
^ ^
controller action
match '/f/:id/find/:find' => 'foo#mobile_method'
presents the params id and finding
or do you want a default value?
match '/m/:id' => 'foo#mobilemethod', :defaults => { :find => true }
精彩评论