Rails 如何重写这个旧的路线map.connect?

发布于 2024-12-04 12:10:32 字数 377 浏览 1 评论 0原文

如何将这条旧路线从 Rails 1.2.6 重写为 Rails 3? :

  # Allow downloading Web Service WSDL as a file with an extension
  # instead of a file named 'wsdl'
  map.connect ':controller/service.wsdl', :action => 'wsdl'

我不知道应该如何使用匹配路线等。

我已经使用过:

  match ':controller/service.wsdl', :action => 'wsdl'

但我认为它工作不正确

How do I rewrite this old route Rails 1.2.6 to Rails 3? :

  # Allow downloading Web Service WSDL as a file with an extension
  # instead of a file named 'wsdl'
  map.connect ':controller/service.wsdl', :action => 'wsdl'

I can´t see how I should use match route etc.

I have used:

  match ':controller/service.wsdl', :action => 'wsdl'

But I dont think it is working correct

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明媚殇 2024-12-11 12:10:32

试试这个:

match '/controller/service.wsdl' => 'controller#service.wsdl', :as => :wsdl

我猜你的控制器没有命名为控制器。如果是,我会重命名它并更改上面的路线。

Try this:

match '/controller/service.wsdl' => 'controller#service.wsdl', :as => :wsdl

I'm guessing that your controller is not named controller. If it is, I'd rename it and change the above route as well.

囍笑 2024-12-11 12:10:32

我还没有找到一个好的解决方案来将 Rails 2 参数化 :controller 和 :action 通用路由转换为更明确的 Rails 3+ 格式。我所要做的就是检查应用程序中的每个排列,并为我需要支持的所有内容添加明确的路线。例如,在您的情况下,如果您有 3 个支持 wsdl 操作的控制器,我将使用 match 或 get 为每个控制器添加一条新路由。

假设您有一个 foo_controller、bar_controller 和 blah_controller 都支持 wsdl 操作,它可能如下所示:

get '/foo/service.wsdl' :to => 'foo#wsdl'
get '/bar/service.wsdl' :to => 'bar#wsdl'
get '/blah/service.wsdl' :to => 'blah#wsdl'

当您需要支持控制器上使用 :action 的每个操作时,这会变得更有趣。

如果有人有更好的方法,我很乐意(并且渴望)听到更好的方法。

I haven't found a good solution to converting Rails 2 parameterized :controller and :action generic routes to the more explicit Rails 3+ format. What I've had to do is go through every permutation in my app and add an explicit route for everything I needed to support. For example, in your case, if you had 3 controllers that supported the wsdl action, I'd add a new route for each using either match or get.

Here's what it might look like, assuming you had a foo_controller, bar_controller, and a blah_controller that all support the wsdl action:

get '/foo/service.wsdl' :to => 'foo#wsdl'
get '/bar/service.wsdl' :to => 'bar#wsdl'
get '/blah/service.wsdl' :to => 'blah#wsdl'

This gets even more fun when you need to support every action on a controller when they use :action.

If anyone has a better method, I'm open (and eager) to hear of a better way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文