From 7da52114ca4b01894cfe4873cb8e8dc5330cef62 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 25 Jan 2013 03:33:48 -0500 Subject: [PATCH] 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 # --- app/controllers/application_controller.rb | 3 +++ app/controllers/posts_controller.rb | 10 +++++++++- app/controllers/topics_controller.rb | 13 ++++--------- app/helpers/application_helper.rb | 12 ++++++++++++ app/views/topics/show.html.erb | 3 ++- config/routes.rb | 2 ++ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0077313..4e3022e 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,7 @@ class ApplicationController < ActionController::Base + + helper :all + protect_from_forgery rescue_from CanCan::AccessDenied do |exception| diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 671ff1d..394bc10 100755 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,9 +1,17 @@ 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]) @@ -18,7 +26,7 @@ class PostsController < ApplicationController @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) + redirect_to topic_path(@post.topic, :page => @post.topic.posts.page.per(10).num_pages, :anchor => @post.id) else render :action => 'new' end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 14c43c3..04c0bea 100755 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,4 +1,7 @@ class TopicsController < ApplicationController + + include ApplicationHelper + load_and_authorize_resource :forum load_and_authorize_resource :topic, :through => :forum, :shallow => true @@ -9,15 +12,7 @@ class TopicsController < ApplicationController @posts = @topic.posts.page(params[:page]).per(10) - @my_blockquote = { - 'Quote' => [ - /\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi, - '
\2\3
', - 'Quote with citation', - '[quote=mike]please quote me[/quote]', - :quote - ], - } + @my_blockquote = block_quote end def create diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ef1c9d2..8e37c76 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,4 +5,16 @@ module ApplicationHelper :confirm => 'Are you sure? Any changes will be lost.' end + def block_quote + return { + 'Quote' => [ + /\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi, + '
\2\3
', + 'Quote with citation', + '[quote=mike]please quote me[/quote]', + :quote + ], + } + end + end diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 4fe454c..3a65f70 100755 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -13,8 +13,9 @@ <% @posts.each do |post| %> <% if !post.user.blank? %> - +