Monday, 15 August 2011

ruby on rails - Route to separate action if request contains a query string -



ruby on rails - Route to separate action if request contains a query string -

i wondering if can have route setup show route parameter goes method , when doesn't have parameter goes show method.

get fruits/:id fruits#show

and

get fruits/id?market=xxx fruits#market

i want because want reloading page via ajax , popstatus add together url in. great create work route way

use route constraint.

get 'fruits/:id', to: 'fruits#market', \ constraints: ->(request) { request.query_parameters.present? } 'fruits/:id', to: 'fruits#show'

you can check if specific parameter present, illustration market:

get 'fruits/:id', to: 'fruits#market', \ constraints: ->(request) { request.query_parameters[:market].present? }

ruby-on-rails ruby ajax

No comments:

Post a Comment