diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 4a91598..9d01982 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -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 @@ -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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 46499a5..9a2359c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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