Created
August 10, 2009 19:20
-
-
Save markiz/165363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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