我有一个名为profile的命名路由,我希望能够以json的形式访问它。但是当我查看rake路由输出时,我发现(:format)丢失了。如何将其添加到命名路由?
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"} profile /:username {:action=>"show", :controller=>"users"}
提前谢谢!
添加 .format 在路径规范中,如下所示:
.format
map.profile '/:profile.:format', :controller => 'users', :action => 'show'
最后你会得到:
profile /:profile(.:format) {:action=>"show", :controller=>"users"}