在我的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