【发布时间】:2014-01-28 10:38:26
【问题描述】:
在我的路由器中我有:
get 'cars/:make', to: 'cars#make'
当人们访问 /cars/dodge 或 /cars/toyota 时,这可以正常工作,但是当人们进入 /cars/make-does-not-exist 时,我更喜欢页面 drop 'make-does-not-exist' from url,并将它们发送到 /cars。
在我的 cars#make 控制器中,我有一些逻辑可以正确设置我的视图:
def make
case params[:make]
when "dodge"
@text = "dodge text"
when "toyota"
@text = "toyota text"
else
@text = "default text"
#how do I send people to /cars, and not /cars/make-does-not-exist
end
render :index #render index with the @text that we just set
end
如何从控制器设置 url?
谢谢!
【问题讨论】:
-
假设
'/cars'路由存在,你应该使用重定向:guides.rubyonrails.org/…
标签: ruby-on-rails routes url-routing