How do I specify “:layout => false” in Rails' respond_with?

后端 未结 7 1876
星月不相逢
星月不相逢 2020-12-13 18:37

I have this setup:

class UsersController < InheritedResources::Base
  respond_to :html, :js, :xml, :json

  def index
    @users = User.all
    respond_wi         


        
7条回答
  •  我在风中等你
    2020-12-13 18:53

    Assuming you need JSON for an Ajax request

    class UsersController < InheritedResources::Base
      respond_to :html, :js, :xml, :json
    
      def index
        @users = User.all
        respond_with(@users, :layout => !request.xhr? )
      end
    end
    

    This seems like the cleanest solution to me.

提交回复
热议问题