生成接受参数的控制器和路由

时间:2021-05-28 11:00:06

I generated a controller from the command line.

我从命令行生成了一个控制器。

The route that's created is

创建的路线是

GET    /cities_by_state/list(.:format)

and I'm trying to get

而且我想要得到

GET    /cities_by_state/list/:id(.:format)

How do I get Rails to create a route that accepts a parameter?

如何让Rails创建接受参数的路由?

(Edited to add slash)

(编辑添加斜杠)

1 个解决方案

#1


3  

get 'cities_by_state/:state' => 'controller#action'

#1


3  

get 'cities_by_state/:state' => 'controller#action'