My hacking journal

Rails content negotiation explained

· by admin · Read in about 1 min · (37 Words)
rails ruby

Explain the following snippet found in a Rails controller:

def index
  @posts = Post.all

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

Useful link to Ruby procs, blocks and lambdas

Comments