ruby-on-rails 自定义路由:如何在Ruby/Rails中使用重定向在自定义路由中正确添加id?

wn9m85ua  于 2023-05-30  发布在  Ruby
关注(0)|答案(1)|浏览(182)

我有一个自定义路由,我需要在重定向调用中的“to:”键值对中添加id。我试过常规方法:

# My Cars
get '/api/cars/profile/:car_id', to: redirect('/cars/profile/:car_id')

我试过插值:

# My Cars
get '/api/cars/profile/:car_id', to: redirect("/cars/profile/#{car_id}")

但仍然没有解决方案

dnph8jn4

dnph8jn41#

最后解决了它:

# My Cars
get '/api/cars/profile/:car_id', to: redirect('/cars/profile/%{car_id}')

相关问题