author avatar

giritharan

Mon May 20 2024

There are two ways to call respond_to: Either we can pass it as a list of symbols or pass a block Block Version:

def index
  @people = Person.all

  respond_to do |format|
    format.json { render json: @people}
    format.xml { render xml: @people }
    format.html { render :index}
  end
end

Symbol version:

def index
  @people = Person.all
  respond_to :json, :xml, :html  
end

#respondto #actionview #rails