From 00934a1e138db3a178f6c374851b90544cfad733 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 25 Feb 2013 09:39:27 -0500 Subject: [PATCH] edit link for original forum post goes to edit topic action --- app/controllers/forum_topics_controller.rb | 1 + app/models/forum_post.rb | 4 ++++ app/views/forum_posts/_forum_post.html.erb | 6 +++++- app/views/forum_topics/_secondary_links.html.erb | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 01ea84765..c9cc1827e 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -26,6 +26,7 @@ class ForumTopicsController < ApplicationController def show @forum_topic = ForumTopic.find(params[:id]) @forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page]) + @forum_posts.all respond_with(@forum_topic) end diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index d7ffe2596..730fb72fd 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -118,6 +118,10 @@ class ForumPost < ActiveRecord::Base ((ForumPost.where("topic_id = ? and created_at <= ?", topic_id, created_at).count) / Danbooru.config.posts_per_page.to_f).ceil end + def is_original_post? + ForumPost.exists?(["id = ? and id = (select _.id from forum_posts _ where _.topic_id = ? order by _.id asc limit 1)", id, topic_id]) + end + def build_response dup.tap do |x| x.body = x.quoted_response diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index c1ebb5cfa..e80e54033 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -27,7 +27,11 @@ <% end %> <% end %> <% if forum_post.editable_by?(CurrentUser.user) %> -
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id) %>
  • + <% if forum_post.is_original_post? %> +
  • <%= link_to "Edit", edit_forum_topic_path(forum_post.topic) %>
  • + <% else %> +
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id) %>
  • + <% end %> <% end %>
  • <%= link_to "Parent", forum_topic_path(forum_post.topic, :page => forum_post.forum_topic_page) %>
  • <%= link_to "Permalink", forum_post_path(forum_post) %>
  • diff --git a/app/views/forum_topics/_secondary_links.html.erb b/app/views/forum_topics/_secondary_links.html.erb index bd5c52087..b2bee9146 100644 --- a/app/views/forum_topics/_secondary_links.html.erb +++ b/app/views/forum_topics/_secondary_links.html.erb @@ -9,9 +9,9 @@
  • |
  • <%= link_to "Reply", new_forum_post_path(:topic_id => @forum_topic.id) %>
  • <% if !@forum_topic.new_record? && @forum_topic.editable_by?(CurrentUser.user) %> -
  • <%= link_to "Edit topic", edit_forum_topic_path(@forum_topic) %>
  • +
  • <%= link_to "Edit", edit_forum_topic_path(@forum_topic) %>
  • <% if CurrentUser.is_moderator? %> -
  • <%= link_to "Delete topic", forum_topic_path(@forum_topic), :remote => true, :method => :delete, :confirm => "Do you want to delete this forum topic?" %>
  • +
  • <%= link_to "Delete", forum_topic_path(@forum_topic), :remote => true, :method => :delete, :confirm => "Do you want to delete this forum topic?" %>
  • <% end %> <% end %> <% end %>