Skip to content

Instantly share code, notes, and snippets.

@visnup
Created February 14, 2010 02:00
Show Gist options
  • Save visnup/303788 to your computer and use it in GitHub Desktop.
Save visnup/303788 to your computer and use it in GitHub Desktop.
a scaffold using respond_with
class PostsController < ApplicationController
respond_to :html, :xml, :json
# GET /posts
# GET /posts.xml
def index
@posts = Post.paginate :page => params[:page]
respond_with @posts do |format|
format.atom
end
end
# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])
respond_with @post
end
# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new
respond_with @post
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.xml
def create
@post = Post.create(params[:post])
respond_with @post
end
# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])
@post.update_attributes(params[:post])
respond_with @post
end
# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_with @post
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment