- def hidecomment
- comment = DiaryComment.find(params[:comment])
- comment.update(:visible => false)
- redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
- end
-
- def unhidecomment
- comment = DiaryComment.find(params[:comment])
- comment.update(:visible => true)
- redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
- end
-
- def comments
- @title = t ".title", :user => @user.display_name
-
- comments = DiaryComment.where(:users => @user)
- comments = comments.visible unless can? :unhidecomment, DiaryEntry
-
- @params = params.permit(:display_name)
-
- @comments = if params[:before]
- comments.where("diary_comments.id < ?", params[:before]).order(:id => :desc)
- elsif params[:after]
- comments.where("diary_comments.id > ?", params[:after]).order(:id => :asc)
- else
- comments.order(:id => :desc)
- end
-
- @comments = @comments.limit(20)
- @comments = @comments.includes(:user)
- @comments = @comments.sort.reverse
-
- @newer_comments = @comments.count.positive? && comments.exists?(["diary_comments.id > ?", @comments.first.id])
- @older_comments = @comments.count.positive? && comments.exists?(["diary_comments.id < ?", @comments.last.id])
- end
-