Files
danbooru/app/controllers/comments_controller.rb
albert 2053e6ad8c * Renamed Post.find_by_tags into Post.tag_match, made into a full fledged scope
* Post.tag_match no longer takes an options hash (use other arel builders instead)
2011-01-28 17:40:22 -05:00

47 lines
1.2 KiB
Ruby

class CommentsController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :only => [:update, :create]
def index
if params[:group_by] == "post"
index_by_post
else
index_by_comment
end
end
def update
@comment = Comment.find(params[:id])
@comment.update_attributes(params[:comment])
respond_with(@comment)
end
def create
@comment = Comment.new(params[:comment])
@comment.post_id = params[:comment][:post_id]
@comment.score = 0
@comment.save
respond_with(@comment) do |format|
format.html do
redirect_to post_path(@comment.post), :notice => "Comment posted"
end
end
end
private
def index_by_post
@posts = Post.tag_match(params[:tags]).commented_before(params[:before_date] || Time.now).limit(8)
respond_with(@posts) do |format|
format.html {render :action => "index_by_post"}
end
end
def index_by_comment
@search = Comment.search(params[:search])
@comments = @search.paginate(:page => params[:page])
respond_with(@comments) do |format|
format.html {render :action => "index_by_comment"}
end
end
end