在我的Rails 2.3.11应用程序中,我想指定路由的默认格式为:xml。据the documentation我可以用:defaults
如何在rails 2.3路径中指定默认值?
map.connect '/myroute', :controller => 'mycontroller',
:action => 'myaction',
:defaults => {:format => :xml}
做到这一点,文件明确表示,这应该工作:
You can also define other defaults in a route by supplying a hash for the :defaults option. This even applies to parameters that are not explicitly defined elsewhere in the route.
但如果我这样做,然后我得到这个错误:
/Users/simon/myproject/vendor/rails/actionpack/lib/action_controller/routing/builder.rb:107:in `assign_route_options':
format: No matching segment exists; cannot assign default (ArgumentError)
我看到a lighthouse ticket已经提出这个问题;受访者指出,它适用于资源而非命名路线;管理员将其错误地标记为已修复,因为他在资源上进行了测试。何哼。
其它地方的建议,我不喜欢这样写道:
map.connect '/myroute', :controller => 'mycontroller',
:action => 'myaction',
:format => :xml
但当时如果我测试它
assert_generates '/myroute', :controller => 'mycontroller',
:action => 'myaction'
我得到告知,没有路由匹配:controller => 'mycontroller', :action => 'myaction'
- 我必须把格式在手边,所以它不是默认的。
如何在rails 2.3路径中指定默认值?我是否需要让他们重新打开票证并实际修复错误?有没有希望,现在Rails 3会出现?
2-3稳定没有补丁,文档或其他https://github.com/rails/rails/issues/6501#issuecomment-5948321这很伤心。 – Vanuan 2012-05-26 18:19:22