Ruby on Rails Socialization gem setup

ruby, ruby-on-rails, ruby-on-rails-4

Solution

I'm the author of Socialization. Here's some code taken from our application. We have a SocializationsController that handles like & follow for every model. It's pretty straightforward.

# routes.rb
## snip ##
resources :users do
  post 'follow',   to: 'socializations#follow'
  post 'unfollow', to: 'socializations#unfollow'
end

resources :categories, only: [:index] do
  post 'follow',   to: 'socializations#follow'
  post 'unfollow', to: 'socializations#unfollow'
end
## snip ##

# socializations_controller.rb
class SocializationsController < ApplicationController
  before_filter :load_socializable

  def follow
    current_user.follow!(@socializable)
    render json: { follow: true }
  end

  def unfollow
    current_user.unfollow!(@socializable)
    render json: { follow: false }
  end

private
  def load_socializable
    @socializable =
      case
      when id = params[:comment_id] # Must be before :item_id, since it's nested under it.
        @community.comments.find(id)
      when id = params[:item_id]
        @community.items.find(id)
      when id = params[:user_id]
        User.find(id)
      when id = params[:category_id]
        @community.categories.find_by_id(id)
      else
        raise ArgumentError, "Unsupported socializable model, params: " +
                             params.keys.inspect
      end
    raise ActiveRecord::RecordNotFound unless @socializable
  end  
end

For mentions, you just have to parse a comment where a mention is present, for example, and manually create the mention with code. It should be fairly straightforward.

Problem

I went through the documentation of the socialization gem and it does not explain thoroughly how to setup the gem up in my routes and controller to have the follow and mention features function properly. I was wondering if anyone could show me how to set up this gem in my routes and controller to have it functioning properly. A thoughtful answer would be greatly appreciated.

Original source