Rails路线/ new(.:format)

假设我有一个WordsController,我明白了

GET /words(.:format) /words#index 

此路由在路由末尾有一个(。:格式),以便我可以选择不同的响应格式。

 GET /words/new(.:format) /words#new 

为什么新动作有(。:格式)?

它不是用条件查询单词,而是为Rails提供不同的格式来响应。 看期? 这样你可以做以下事情: /words.json并获得JSON响应,或/words.csv并获得CSV响应。

你是对的,没有理由拥有/words/new.jsonurl,但Rails只是将(.:format)到所有url,以防你需要/想要某种格式。