我怎样才能获得一个 rails 路线来保留扩展名作为 id 的一部分? [英] How can I get a rails route to keep the extension as part of the id?

查看:54
本文介绍了我怎样才能获得一个 rails 路线来保留扩展名作为 id 的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了以下路线:

map.resources :images, :only => [ :index, :new, :destroy ]

当我执行 rake routes 时,我得到以下信息:

when I do a rake routes I get the following:

image DELETE /images/:id(.:format) {:action=>"destroy", :controller=>"images"}

我的问题是,我想使用文件名作为我的 :id 包括任何扩展名.目前我的 id 正在进入控制器减去扩展.有什么办法可以自定义上面的map.resources生成如下路径:

My problem is, I would like to use file names as my :id including any extension. At the moment my ids are getting to the controller minus the extension. Is there any way I can customize the above map.resources to generate the following path:

image DELETE /images/:id {:action=>"destroy", :controller=>"images"}

即没有用作 :format 的扩展名?

i.e. not have the extension used as :format?

推荐答案

. 字符在 ActionController::Routing::SEPARATORS 中定义,它列出了要使用的特殊字符拆分网址.

The . character is defined in ActionController::Routing::SEPARATORS, which lists special characters to split the URL on.

如果你想避免在 .s 处分割 URL,你需要传递一个 :constraints =>;{ :id =>/regexp/} map.resources 的参数.

If you want to avoid splitting the URL at .s, you need to pass a :constraints => { :id => /regexp/ } argument to map.resources.

我的相关问答了解更多信息.

这篇关于我怎样才能获得一个 rails 路线来保留扩展名作为 id 的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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