Skip to content

Instantly share code, notes, and snippets.

@tubbo
Created November 10, 2009 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tubbo/230694 to your computer and use it in GitHub Desktop.
Save tubbo/230694 to your computer and use it in GitHub Desktop.
blog/posts_controller
class Blog::PostsController < ApplicationController
before_filter :authorization_required, :except => [:index, :show]
layout 'application', :except => :feed
# GET /blog/posts
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
# GET /blog/post/1
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
# GET /blog/post/new
def new
@post = Post.new
@categories = Category.all
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
# GET /blog/post/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /blog/posts
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(@post) }
else
format.html { render :action => "new" }
end
end
end
# PUT /blog/posts/1
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
flash[:notice] = 'Post was successfully updated.'
format.html { redirect_to(@post) }
else
format.html { render :action => "edit" }
end
end
end
# DELETE /blog/posts/1
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(blog_posts_url) }
end
end
# GET /blog/posts/feed.rss
# GET /blog/posts/feed.atom
def feed
@posts = Posts.find(:all, :order => 'created_ata DESC')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment