From 7483ad2e28c60d6c153201d1302ad5ce136c0a55 Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 11 Sep 2011 15:15:16 -0400 Subject: [PATCH] comment threshold link now hitting the correct action --- app/controllers/comments_controller.rb | 9 +++++++++ app/models/comment.rb | 1 + app/views/comments/index_for_post.js.erb | 1 + app/views/notes/revert.js.erb | 1 + 4 files changed, 12 insertions(+) create mode 100644 app/views/comments/index_for_post.js.erb create mode 100644 app/views/notes/revert.js.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 986359335..fad8a6fdc 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -5,6 +5,8 @@ class CommentsController < ApplicationController def index if params[:group_by] == "post" index_by_post + elsif request.format == Mime::JS + index_for_post else index_by_comment end @@ -35,6 +37,13 @@ class CommentsController < ApplicationController end private + def index_for_post + @post = Post.find(params[:post_id]) + @comments = @post.comments + @comments = @comments.visible unless params[:include_hidden] + render :action => "index_for_post" + end + def index_by_post @posts = Post.commented_before(Time.now).tag_match(params[:tags]).paginate(params[:page]) respond_with(@posts) do |format| diff --git a/app/models/comment.rb b/app/models/comment.rb index 2d2658faa..9dfff6fcb 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -12,6 +12,7 @@ class Comment < ActiveRecord::Base scope :recent, :order => "comments.id desc", :limit => 6 scope :body_matches, lambda {|query| where("body_index @@ plainto_tsquery(?)", query).order("comments.id DESC")} scope :hidden, lambda {|user| where("score < ?", user.comment_threshold)} + scope :visible, lambda {|user| where("score >= ?", user.comment_threshold)} scope :post_tag_match, lambda {|query| joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query)} scope :for_user, lambda {|user_id| where("creator_id = ?", user_id)} diff --git a/app/views/comments/index_for_post.js.erb b/app/views/comments/index_for_post.js.erb new file mode 100644 index 000000000..720309a40 --- /dev/null +++ b/app/views/comments/index_for_post.js.erb @@ -0,0 +1 @@ +$("div.comments-for-post[data-post-id=<%= @post.id %>] div.notices").hide(); diff --git a/app/views/notes/revert.js.erb b/app/views/notes/revert.js.erb new file mode 100644 index 000000000..2765ee13d --- /dev/null +++ b/app/views/notes/revert.js.erb @@ -0,0 +1 @@ +window.location.reload();