Rails 3 - Restricting formats for action in resource routes

前端 未结 4 1833
时光说笑
时光说笑 2020-12-23 20:06

I have a resource defined in my routes.

resources :categories

And I have the following in my Category controller:

  def sho         


        
4条回答
  •  遥遥无期
    2020-12-23 20:50

    I found that this seemed to work (thanks to @Pan for pointing me in the right direction):

    resources :categories, :except => [:show]
    resources :categories, :only => [:show], :defaults => { :format => 'json' }
    

    The above seems to force the router into serving a format-less request, to the show action, as json by default.

提交回复
热议问题