我有一个名为 profile 的命名路由,我希望能够以 json 的形式访问它。但是当我查看我的 rake 路由输出时,我发现 (.:format) 丢失了。如何将它添加到命名路由?
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
profile /:username {:action=>"show", :controller=>"users"}
提前致谢!
最佳答案
在您的路径规范中添加 .format
,如下所示:
map.profile '/:profile.:format', :controller => 'users', :action => 'show'
然后你会得到:
profile /:profile(.:format) {:action=>"show", :controller=>"users"}
关于ruby-on-rails - 如何添加:format options to a named route in Rails?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2438707/