Yang
Yang

Reputation: 1923

Is there any way in RoR to add some optional parameters in route?

I have a route here:

get  'api/users/:id/friends/:fid', to: 'friends#show'

I want to make the :fid as optional parameter. Any Ideas?

Upvotes: 1

Views: 51

Answers (2)

djaszczurowski
djaszczurowski

Reputation: 4515

just put it in parenthesis

get  'api/users/:id/friends(/:fid)', to: 'friends#show'

more information in guideline (paragraph 3.1) http://guides.rubyonrails.org/routing.html

Upvotes: 6

user5633750
user5633750

Reputation:

Please try the code as below:

get  'api/users/:id/friends(/:fid)', to: 'friends#show'

Upvotes: 4

Related Questions