Skip to content

Instantly share code, notes, and snippets.

@ctdk
Created May 27, 2009 04:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ctdk/118462 to your computer and use it in GitHub Desktop.
class StoryController < ApplicationController
#require 'utility'
def index
@story = Story.get(params[:id])
#@comments = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id)
#@comments = Comment.find_by_sql(['SELECT comments.id, subject, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id])
# experiment...
clist = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id)
chash = Hash.new
@comments = Array.new
# order this shit, and quick
clist.each do |c|
chash[c.parent_id] = Array.new if chash[c.parent_id].nil?
chash[c.parent_id].push(c)
end
cproc = Proc.new { |s| unless (chash[s].nil?); chash[s].each { |i| @comments.push(i); cproc.call(i.id)} end }
#chash.each_key { |k| cproc.call(k) }
cproc.call(0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment