[英]Custom routing and get ids from url
我有一个模型名称“ profit”,它有一个表名称profits和表的“价格”,“出售”,“毛利润”的三列
现在在我的index.html.erb页面中,我可以选择显示为
<td><%= link_to 'Show', profit %></td>
当我单击显示链接时,我进入显示页面,链接变为
http://localhost:3000/students/1
http://localhost:3000/students/2
那就是我正在获取利润表的ID,但我需要价格并按如下所示在我的网址中出售
http://localhost:3000/students/3/5
其中3将被出售而5将是价格
我必须做些什么更改才能获得此URL,以及如何在控制器的show action中从URL获得价格和出售?
在routes.rb中创建这样的路由。 将此放在资源之前:学生
get '/students/:sell/:price, to: "students#show"
现在运行耙路,看看它将创建和使用什么帮助器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.