
#BLOCCIT ASSIGNMENT 42 CODE#
With the code above, you can see that popular_topics (aka "hot topics") and top_posts (aka "popular posts") use the counters in descending order.

In app/controllers/welcome_controller.rb:ĭef = Topic.reorder('posts_count = Post.reorder('comments_count = Comment.order('created_at DESC').limit(2) Note: I decided to order popular posts by number of comments rather than overall votes because I thought, what if there's a post that people really hate and downvote, but that post has all the action because everyone is commenting on it? That means whatever topic had the most posts would be at the top of my list, and the post with most comments would be at the top. Now that I had my counters set up, I could write a simple custom scope to rank the topics and posts from the highest number in the counter column to the lowest. Writing a custom scope to order topics and posts by rank (Seriously, thank the universe for version control!).Ĭlass AddCommentsCount false, default: 0Ģ.

The thought of thoroughly messing it up and destroying all of my hard work was holding me back, but then I just had to remind myself: this is what version control is for. I liked this idea a lot, but I was a bit nervous about going outside the curriculum to make changes to my database. Essentially, instead of relying on the active record associations for these lists, I could simply create a column in the topics table that would hold the number of posts belonging to each topic, and again in the posts table to hold the number of comments. However, as I searched Google and read through Stack Overflow solutions, I kept seeing counter columns being discussed. Tracking how many posts belonged to each topic and how many comments belonged to each postīecause my database was already set up with the belongs to/has many active record associations between posts/topics and comments/posts, I knew there was a way I could query the database to create these lists.

The largest of these features is what's on the front page of Bloccit, which is a collection of recent activity on the site in the form of hot topics, popular posts and recent comments: I found that as I got toward the end of the project, I had a lot of ideas for features I wanted to implement that weren't included in the curriculum at all, and I simply was not satisfied without them. Sometimes it was simply implementing the feature again but in a different way, and sometimes it would be refactoring or customizing the feature.
#BLOCCIT ASSIGNMENT 42 HOW TO#
For example, for each checkpoint, Bloc would walk me through how to implement a feature, but then at the end of that checkpoint, I'd be given an assignment to complete on my own. Since this was the first project of Bloc's back-end curriculum, a lot of it was mostly spelled out. In addition to standard users, there are also administrators who can be sure to keep everything in line with the ability to edit and delete anything that might not be welcome on the site.

Just like with Reddit, users make an account, write posts under topics, comment on posts, vote posts up or down to give each post a number that tracks its reputation, and mark posts as favorites to receive notifications of new comments on those posts. What's more, I had a suspicion that I'd love working with data (like, I'm slightly obsessed with looking at web analytics, and I actually enjoy tracking my budget and financial goals), and learning how to build a database, seed it with data, then use the Ruby console from the command line to access and manipulate that data made me literally ask out loud, "Ruby, where have you been all my life?!"Īs you'll see with this project, Bloccit is meant to be similar to the popular forum website Reddit. (Obviously, there's much more to it than that, but as a beginner, that was the aspect of Ruby that originally excited me.)Īs a 50% left brain / 50% right brain person, I love that there's both an art and a logic to coding, and working with Ruby really brought that home for me. Basically, instead of having to accommodate JavaScript's dependence on semicolons, parentheses, brackets and other complicated syntax markers, you can essentially write English with Ruby. First of all, programmers aren't joking when they say Ruby was written to be programmer-friendly. And thus began my love affair with Ruby! After spending so much time with JavaScript, it was kind of difficult to make the change to Ruby - but only kind of, and not for long. Portfolio: Development Bloccit: A forum web app with topics, votes and favoritesĪfter focusing on front-end web development with projects including Bloc Jams and Bloc Chat, it was time to transfer over to back-end web development.
