打印

关于 respond_to的问题

关于 respond_to的问题

def index
  @posts = Post.find(:all)

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


谁知道这个@posts block内部的
只看见format.xml 时才传递了@posts
而其他的format.html 没有看见有引用@posts

谁能给我讲下这个函数的具体流程!

谢谢

TOP

respond_to src code:

def respond_to(*types, &block)
   raise ArgumentError, "respond_to takes either types or a block, never both" unless types.any? ^ block
   block ||= lambda { |responder| types.each { |type| responder.send(type) } }
   responder = Responder.new(self)
   block.call(responder)
   responder.respond
  end


//关于源码中的这种是什么意思??
block ||= lambda { |responder| types.each { |type| responder.send(type) } }

[ 本帖最后由 bzero 于 2008-3-25 10:45 编辑 ]

TOP

2008-11-23 21:58 Crawled by CCBot/1.0 (+http://www.commoncrawl.org/bot.html) @38.103.63.61