jpw
jpw

Reputation: 19247

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

Upvotes: 1

Views: 2225

Answers (2)

mark
mark

Reputation: 10564

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 }

Upvotes: 2

Dylan Markow
Dylan Markow

Reputation: 124419

This should do this trick:

match '/f/:id' => 'foo#mobilemethod', :defaults => {:find => true}

Upvotes: 4

Related Questions