As a new comer for ruby, I feel confused for this snippet:

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @posts }
    end

I understand that if format is .html, it will give html response and if
format is .xml, it will give out xml response.

So this block "do |format| ... end" is case switch like in C++. I have
difficulty to understand though in ruby, if the user passing .html, as a
sequential execution (notice in ruby this is not a case switch
statement), what prevent ruby from executing "format.xml  { render :xml
=> @posts }" line?

To my feeling (though I know I am wrong for sure), these two lines will
always be executed no matter what kind of format is passed in:

      format.html # index.html.erb
      format.xml  { render :xml => @posts }

Please help.

-- 
Posted via http://www.ruby-forum.com/.