class PostsController < ApplicationController include ApplicationHelper load_and_authorize_resource :topic load_and_authorize_resource :post, :through => :topic, :shallow => true before_filter :check_for_cancel#, :only[:create, :update] def show @topic = @post.topic @my_blockquote = block_quote end def new if params[:quote] quote_post = Post.find(params[:quote]) if quote_post @post.body = "[quote=#{quote_post.user.username}]#{quote_post.body}[/quote]" end end end def create check_for_cancel @post.user ||= current_user if @post.save flash[:notice] = "Post was successfully created." redirect_to topic_path(@post.topic, :page => @post.topic.posts.page.per(10).num_pages, :anchor => @post.id) else render :action => 'new' end end def update if @post.update_attributes(params[:post]) flash[:notice] = "Post was successfully updated." redirect_to topic_path(@post.topic, :page => @post.topic.posts.page.per(10).num_pages, :anchor => @post.id) end end def destroy if @post.topic.posts_count > 1 if @post.destroy flash[:notice] = "Post was successfully destroyed." redirect_to topic_path(@post.topic) end else if @post.topic.destroy flash[:notice] = "Topic was successfully deleted." redirect_to forum_path(@post.forum) end end end def check_for_cancel if params[:commit] == 'cancel' redirect_to topic_path(@post.topic) end end end