August 21, 2015 Log No. 378

DiscoverIT

To continue with my series of really terribly named Rail projects, we made a RedditLite spinoff called DiscoverIt. (Can you believe it actually took a thesaurus to come up with that awful name?) The project itself was relatively straightforward until the end, but afforded good practice with setting up a shell of a site, complete with user sessions, ability to submit/edit/remove content, etc. The “cross-posting” feature was a cool new thing in that it introduced us to yet another amazing ActiveRecord feature, the ability to not only auto-populate foreign keys, but even create rows in many-to-many tables, based purely on associations. Once again, I didn’t really think it would work, but why do I ever doubt ActiveRecord?

At the end of the day we were faced with presenting “nested comments” and “nested comment threads” and that stumped us for a bit. I took it home and after some fiddling, figured it out.

def display_children_comments(comment) a="" a += <<-HTML <li class="clearfix"> <div class="vote_container clearfix"> <form action="#{ upvote_comment_url(comment) }" method="post"> #{form_auth} <button>^</button> </form> <p>#{comment.score}</p> <form action="#{ downvote_comment_url(comment) }" method="post"> #{form_auth} <button>v</button> </form> </div> <h5><a href="#{user_url(comment.author)}">#{comment.author.username}</a> @ #{comment.created_at.to_s(:long)}:</h5> <p>#{comment.content}</p> <p class="reply_link"><a href="#{comment_url(comment)}">reply</a></p> </li> HTML if has_children?(comment) a += "<ul>" @comment_hash[comment.id].each do |c2| a += "#{display_children_comments(c2)}" end a += "</ul>" end return a.html_safe end

So got a nice sense of closure on it. Site is still pretty bare bones though. Thinking about sprucing it up a bit. Maybe during our upcoming catch up day.


Leave a Reply

Your email address will not be published. Required fields are marked *

*