开发者

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 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜