Skip to content

Commit

Permalink
teensy bit more controller cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Feb 2, 2009
1 parent f44983d commit 07a4526
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 10 additions & 5 deletions app/controllers/application.rb
Expand Up @@ -11,10 +11,8 @@ class Application < ActionController::Base

filter_parameter_logging :password, :password_confirmation

def expire_path(file)
file = File.join(Rails.root.to_str, 'public', file)
FileUtils.rm_rf(file) if File.exists?(file)
logger.info("Expired cache: #{file}")
def current_post
@current_post ||= Post.find_by_permalink(params[:id], :include => :comments) || Post.find(params[:id])
end

protected
Expand All @@ -34,5 +32,12 @@ def not_found
cookies[:error] = "Sorry but that post could not be found."
redirect_to root_path and return
end


private

def expire_path(file)
file = File.join(Rails.root.to_str, 'public', file)
FileUtils.rm_rf(file) if File.exists?(file)
logger.info("Expired cache: #{file}")
end
end
16 changes: 10 additions & 6 deletions app/controllers/posts_controller.rb
Expand Up @@ -22,25 +22,29 @@ def index
@posts = post_repo.paginate_index(:page => params[:page])
respond_to do |format|
format.html { render :template => 'posts/index.html.erb' }
format.rss { render :template => 'posts/index.rss.builder' }
format.xml { render :xml => @posts }
format.rss { render :template => 'posts/index.rss.builder' }
format.xml { render :xml => @posts }
end
end

# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find_by_permalink(params[:id], :include => :comments) || Post.find(params[:id])
redirect_to root_path and return unless @post.type.match(/Article|Snippet/)
@comment = flash[:comment] || @post.comments.build
redirect_to root_path and return unless current_post.type.match(/Article|Snippet/)

@comment = flash[:comment] || current_post.comments.build
respond_to do |format|
format.html { render :template => 'posts/show.html.erb' }
format.xml { render :xml => @post }
format.xml { render :xml => current_post }
end
end

private

def current_post
@current_post ||= Post.find_by_permalink(params[:id], :include => :comments) || Post.find(params[:id])
end

def post_type
:posts
end
Expand Down

0 comments on commit 07a4526

Please sign in to comment.