Files
forum/app/controllers/topics_controller.rb
Ricky Barrette 7da52114ca Added post anchors and show post.
when a new post is created, the page is now scrolled to is via its
anchor

created a show post route, and view.

added a post number to post view, with link.

need to change displayed post number from post id, to reply #
2013-01-25 03:33:48 -05:00

50 lines
1.0 KiB
Ruby
Executable File

class TopicsController < ApplicationController
include ApplicationHelper
load_and_authorize_resource :forum
load_and_authorize_resource :topic, :through => :forum, :shallow => true
before_filter :check_for_cancel
def show
@topic.hit! if @topic
@posts = @topic.posts.page(params[:page]).per(10)
@my_blockquote = block_quote
end
def create
@topic.user ||= current_user
if @topic.save
flash[:notice] = "Topic was successfully created."
redirect_to topic_url(@topic)
else
render :action => 'new'
end
end
def update
if @topic.update_attributes(params[:topic])
flash[:notice] = "Topic was updated successfully."
redirect_to topic_url(@topic)
end
end
def destroy
if @topic.destroy
flash[:notice] = "Topic was deleted successfully."
redirect_to forum_url(@topic.forum)
end
end
def check_for_cancel
if params[:commit] == 'cancel'
redirect_to @topic.new_record? ? @forum : @topic
end
end
end