是否可以从路由中删除(。:format)我的资源)? rails2.3 [英] Is it possible to remove (.:format) from from routes for my resources)? rails2.3
问题描述
如果我在route.rb中执行 map.resources:users
,则我得到的路由在每个路由(耙式路由)的末尾都有(。:format)。
if I do map.resources :users
in routes.rb, the routes I get have (.:format) at the end of each route (rake routes).
我如何在Rails 2.3中摆脱这种情况?
How do I get rid of this in rails 2.3?
我很确定在3.1.1中我可以做类似:format => false的事情。在2.3中可用吗?我可以模仿一个猴子补丁吗:format => false?
I'm pretty sure in 3.1.1 I can do something like :format=>false. Is this available in 2.3? Is there a monkey patch I can do to mimic :format=>false?
谢谢。
推荐答案
猴子已打补丁。等等。我真的是真的想要更改默认行为,但考虑了潜在的未来开发人员的敏感性。
Monkey patched. Blah. I really, really wanted to change the default behavior, but took into consideration potential future developers' sensitivities.
地图.resource(s)...,:format => false
现在不包含路由格式
config / initializers /resources.rb:
config/initializers/resources.rb:
module ActionController
module Resources
private
def map_resource_routes(map, resource, action, route_path, route_name = nil, method = nil, resource_options = {} )
if resource.has_action?(action)
action_options = action_options_for(action, resource, method, resource_options)
formatted_route_path = (resource.options[:format] == false ? route_path : "#{route_path}.:format")
if route_name && @set.named_routes[route_name.to_sym].nil?
map.named_route(route_name, formatted_route_path, action_options)
else
map.connect(formatted_route_path, action_options)
end
end
end
end
end
我所做的更改是在这里:
The change I made is here:
formatted_route_path = (resource.options[:format] == false ? route_path : "#{route_path}.:format")
它曾经只是 formatted_route_path =#{route_path} .: format
要使其适用于所有路线,在routes.rb中,我只用 map.with_options:format => false包裹了所有路线做| map | ...结束
To get it to apply to all routes, in routes.rb, I just wrapped all routes with map.with_options :format=>false do |map| ... end
这篇关于是否可以从路由中删除(。:format)我的资源)? rails2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!