Rails 3 路由 - 从 routes.rb 传递参数 [英] Rails 3 routing - passing params from routes.rb

查看:19
本文介绍了Rails 3 路由 - 从 routes.rb 传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 rails 2.3.5 中,您可以在 routes.rb 文件中执行以下操作:

In rails 2.3.5 you could do something like this inside the routes.rb file:

map.root :controller => "pages", :action => "show", :id => 3

在 rails 3 中,我没有找到任何传递特定参数的方法(例如在 rails 2.3.5 中使用 :id => 3).

In rails 3 I haven't found any way to pass a specific parameter (like in rails 2.3.5 with :id => 3).

我知道我可以从控制器处理它并得到相同的结果(我做到了),但我想知道是否有办法在 routes.rb 中的 rails 3 中做同样的事情,或者是否有改变,因为出于某种原因,这是更好的做法吗?

I know I can handle it from the controller and have the same result (which I did), but I was wondering if there is a way to do the same thing in rails 3 from the routes.rb or has it changed because it is better practice for some reason?

推荐答案

您确定以下内容不起作用吗?

Are you sure the following doesn't work?

root :to => "pages#show", :id => 3

这篇关于Rails 3 路由 - 从 routes.rb 传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆