Forum: Ruby on Rails problem in understanding respond_to in rails 2.0 and above

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3d9e26d3be3e7fcf93aca6574bc77a20?d=identicon&s=25 Tushar Gandhi (gandhi-tush)
on 2009-04-08 09:52
Hi,
I am using rails 2.2.

I have created a controller using "ruby script/generate scaffold
person".
This created the code like this.

def index
    @people = Person.find(:all)

    respond_to do |format|
      format.html
      format.xml { render :xml => @people.to_xml }
    end
 end

 I am new in rails 2.0 and above. I worked on rails 1.2.3. I an not able
to understand what is the use of

"respond_to do |format|
      format.html
      format.xml { render :xml => @people.to_xml }
 end" this code.

Can anyone focus for me?
Help appreciated.

Also there are some code like this
"respond_to do |format|
      format.html
      format.js
      format.xml { render :xml => @people.to_xml }
 end"

Thanks,
Tushar
This topic is locked and can not be replied to.