Rails 3 - Restricting formats for action in resource routes

前端 未结 4 1831
时光说笑
时光说笑 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:46

    You could do the following in your routes.rb file to make sure that only the show action is constrained to json or xml:

    resources :categories, :except => [:show]
    resources :categories, :only => [:show], :constraints => {:format => /(json|xml)/}
    

    If this doesn't work you could try explicitly matching the action:

    resources :categories, :except => [:show]
    match 'categories/:id.:format' => 'categories#show', :constraints => {:format => /(json|xml)/}
    

提交回复
热议问题