2

So I'm trying out the Public Activity gem for a notification timeline and I don't understand why I'm getting the NameError , uninitialized constant message. Here's the error I'm getting:

NameError in ActivitiesController#index
uninitialized constant ActivitiesController::PublicActivity

app/controllers/activities_controller.rb:3:in `index'

uninitialized constant ActivitiesController::PublicActivity

Here's my controller code where the error is said to be:

    class ActivitiesController < ApplicationController
      def index
       @activities = PublicActivity::Activity.order("created_at desc")
      end
     end

I'm trying this out based on a rails cast: http://railscasts.com/episodes/406-public-activity And as far as I know I've done the same thing as the one on it.

There isn't any activity model, but here's the post and comments model where I used the PublicActivity module:

POST MODEL:

class Post < ActiveRecord::Base
  include PublicActivity::Model
  tracked

COMMENT MODEL

class Comment < ActiveRecord::Base
    include PublicActivity::Model
tracked

belongs_to :post
belongs_to :user
end
Pau
  • 55
  • 1
  • 3
  • 7

1 Answers1

1

according to gem sources

 def load_orm
      require "public_activity/orm/#{@@orm.to_s}"
      m = "PublicActivity::ORM::#{@@orm.to_s.classify}".constantize
      ::PublicActivity.const_set(:Activity,  m.const_get(:Activity))
      ::PublicActivity.const_set(:Adapter,   m.const_get(:Adapter))
      ::PublicActivity.const_set(:Activist,  m.const_get(:Activist))
      ::PublicActivity.const_set(:Trackable, m.const_get(:Trackable))
    end

You should use next code

  @activities = ::PublicActivity::Activity.order("created_at desc")

Also ensure that you installed gem with bundle, check bundle show public_activity

Fivell
  • 11,829
  • 3
  • 61
  • 99