Skip to content

Instantly share code, notes, and snippets.

@markiz
Created August 10, 2009 19:20
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 markiz/165363 to your computer and use it in GitHub Desktop.
Save markiz/165363 to your computer and use it in GitHub Desktop.
class Blogs < Application
before :ensure_authenticated
before :find_blogs, :only => :index
before :find_blog, :only => [:show, :edit, :update]
before :create_blog, :only => [:create, :new]
before :find_posts, :only => :show
def nav
return "blogs/nav" if !['index','new'].include?(params[:action]) && @blog.author == session.user
"layout/nav"
end
def index
render :index
end
def show
provides :rss
@rss = "/blogs/#{id}.rss"
display @blog
end
def edit
display @blog
end
def update
@blog.update_attributes(params[:blog])
redirect url :blog, @blog
end
def new
display @blog
end
def create
@blog.update_attributes(params[:blog])
redirect url :blog, :id => @blog.id
end
# finders / creators
def find_blog
@blog = Blog.get(params[:id])
raise NotFound unless @blog
end
def find_blogs
@blogs = Blog.page params[:page], :order => [:id.desc]
end
def create_blog
@blog = Blog.new
end
def find_posts
@posts = Post.page params[:page]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment