Skip to content

Commit

Permalink
Refactor posts controller to use Responder
Browse files Browse the repository at this point in the history
  • Loading branch information
jm committed Feb 5, 2010
1 parent 8f27fe5 commit 53846f9
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions app/controllers/posts_controller.rb
@@ -1,35 +1,28 @@
class PostsController < ApplicationController
respond_to :html, :xml

# GET /posts
# GET /posts.xml
def index
@posts = Post.all

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

# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
respond_with @post
end

# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
respond_with @post
end

# GET /posts/1/edit
Expand All @@ -42,31 +35,17 @@ def edit
def create
@post = Post.new(params[:post])

respond_to do |format|
if @post.save
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
format.xml { render :xml => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
flash[:notice] = 'Post was successfully created.' if @post.save
respond_with @post
end

# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])

respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to(@post, :notice => 'Post was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
flash[:notice] = 'Post was successfully updated.' if @post.update_attributes(params[:post])
respond_with @post
end

# DELETE /posts/1
Expand All @@ -75,9 +54,6 @@ def destroy
@post = Post.find(params[:id])
@post.destroy

respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
respond_with @post
end
end

0 comments on commit 53846f9

Please sign in to comment.