我定义了以下路线:
map.resources :images, :only => [ :index, :new, :destroy ]
当我做一个rake routes
我得到以下信息:
image DELETE /images/:id(.:format) {:action=>"destroy", :controller=>"images"}
我的问题是,我想使用文件名作为我的:id
包括任何扩展。目前我的 ID 正在获取控制器减去扩展名。有什么方法可以自定义上面的map.resources来生成以下路径:
image DELETE /images/:id {:action=>"destroy", :controller=>"images"}
即没有使用扩展名:format
?
The .
字符定义于ActionController::Routing::SEPARATORS
,其中列出了用于分割 URL 的特殊字符。
如果您想避免在以下位置分割 URL.
s,你需要通过:constraints => { :id => /regexp/ }
论证map.resources
.
See 我的相关问题和解答 https://stackoverflow.com/questions/948886/rails-restful-resources-using-to-param-for-a-field-that-contains-separator-charac了解更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)