diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ccc79f869..986359335 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -21,10 +21,7 @@ class CommentsController < ApplicationController end def create - @comment = Comment.new(params[:comment]) - @comment.post_id = params[:comment][:post_id] - @comment.score = 0 - @comment.save + @comment = Comment.create(params[:comment]) respond_with(@comment) do |format| format.html do redirect_to post_path(@comment.post), :notice => "Comment posted" diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 3d3e02781..b0705ef6b 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -15,7 +15,7 @@ class PoolsController < ApplicationController def index @search = Pool.search(params[:search]) - @pools = @search.paginate(:page => params[:page]) + @pools = @search.paginate(params[:page]) respond_with(@pools) end @@ -25,9 +25,7 @@ class PoolsController < ApplicationController def show @pool = Pool.find(params[:id]) - @post_set = PostSets::Base.new(:id => @pool, :page => params[:page]) - @post_set.extend(PostSets::Numbered) - @post_set.extend(PostSets::Pool) + @post_set = PostSets::Pool.new(@pool, params[:page]) respond_with(@pool) end diff --git a/app/logical/post_sets/pool.rb b/app/logical/post_sets/pool.rb new file mode 100644 index 000000000..a091b99d7 --- /dev/null +++ b/app/logical/post_sets/pool.rb @@ -0,0 +1,31 @@ +module PostSets + class Pool < Base + attr_reader :pool, :page, :posts + + def initailize(pool, page) + @pool = pool + @page = page + @posts = pool.posts(:offset => offset, :limit => limit) + end + + def offset + ([page.to_i, 1].max - 1) * limit + end + + def limit + Danbooru.config.posts_per_page + end + + def tag_array + ["pool:#{pool.id}"] + end + + def tag_string + tag_array.join("") + end + + def presenter + @presenter ||= PostSetPresenters::Pool.new(self) + end + end +end diff --git a/app/models/comment.rb b/app/models/comment.rb index dca3e5af1..ef2bafdd5 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -6,7 +6,7 @@ class Comment < ActiveRecord::Base has_many :votes, :class_name => "CommentVote", :dependent => :destroy before_validation :initialize_creator, :on => :create after_save :update_last_commented_at - attr_accessible :body + attr_accessible :body, :post_id attr_accessor :do_not_bump_post scope :recent, :order => "comments.id desc", :limit => 6 diff --git a/app/presenters/post_set_presenters/pool.rb b/app/presenters/post_set_presenters/pool.rb new file mode 100644 index 000000000..002be2862 --- /dev/null +++ b/app/presenters/post_set_presenters/pool.rb @@ -0,0 +1,32 @@ +module PostSetPresenters + class Pool + attr_accessor :tag_set_presenter + + def initialize(pool_set) + @pool_set = pool_set + @tag_set_presenter = TagSetPresenter.new( + RelatedTagCalculator.calculate_from_sample_to_array( + pool_set.tag_string + ).map {|x| x[0]} + ) + end + + def tag_list_html(template) + tag_set_presenter.tag_list_html(template) + end + + def post_previews_html(template) + html = "" + + if pool_set.posts.empty? + return template.render(:partial => "post_sets/blank") + end + + pool_set.posts.each do |post| + html << PostPresenter.preview(post) + end + + html.html_safe + end + end +end diff --git a/app/views/notes/index_by_note.html.erb b/app/views/notes/index_by_note.html.erb index 8e9c749a9..e606e94b9 100644 --- a/app/views/notes/index_by_note.html.erb +++ b/app/views/notes/index_by_note.html.erb @@ -1,6 +1,6 @@
| Post | diff --git a/app/views/pools/_secondary_links.html.erb b/app/views/pools/_secondary_links.html.erb index c8320d96d..fd1957600 100644 --- a/app/views/pools/_secondary_links.html.erb +++ b/app/views/pools/_secondary_links.html.erb @@ -3,7 +3,7 @@
|---|