📚 Blog Archive

A Social Network in Rails: Comments

· Miguel Parramón · blogger

Tags: a social network in rails, Ruby on Rails

This post is part of an ongoing feature about creating a social network in Rails.

This time, we’re adding comments to our Photo model, as presented in the elegant permalinks post. First of all, I looked for a gem to do this job for us, and found acts_as_commentable. Its setup goes something like this:

Add the gem to our Gemfile, and run `bundle install`:

gem ‘acts_as_commentable’

Generate the tables and migrate the DB:

$ rails g comment $ rake db:migrate

Add the comments to our Photo model:

class Photo < ActiveRecord::Base acts_as_commentable end

By doing this, we get the following interface to the comments in our photos:
Read more »

View original post →