0

I installed the public_activity gem following the railscasts tutorial. The activities page in the browser is returning an object instead of the actual event that the activity is referring to.

class ActivitiesController < ApplicationController

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

Migration responsible for creating a table with activities:

class CreateActivities < ActiveRecord::Migration
  # Create table
  def self.up
    create_table :activities do |t|
      t.belongs_to :trackable, :polymorphic => true
      t.belongs_to :owner, :polymorphic => true
      t.string  :key
      t.text    :parameters
      t.belongs_to :recipient, :polymorphic => true

      t.timestamps
    end

    add_index :activities, [:trackable_id, :trackable_type]
    add_index :activities, [:owner_id, :owner_type]
    add_index :activities, [:recipient_id, :recipient_type]
  end

  # Drop table
  def self.down
    drop_table :activities
  end
end
frandroid
  • 1,343
  • 16
  • 26
Alex Cowley
  • 123
  • 4
  • 11

1 Answers1

0

Have you tried this to see if it works:

Activity.order("created_at desc")

I am just wondering if you have namespacing setup correctly.

I am not familiar with the way you are trying to namespace. Maybe give this a try:

Module PublicActivity
 class Activity

 end
end

or

 class PublicActivity::Activity < ActiveRecord::Base (or whatever class you want)

 end
smcdrc
  • 1,671
  • 2
  • 21
  • 29
  • Yes its in my ActivitiesController its the first code I posted – Alex Cowley Sep 11 '13 at 20:56
  • I am referring to the Model. Can you paste the content of your the model? – smcdrc Sep 11 '13 at 21:57
  • class Event < ActiveRecord::Base include PublicActivity::Model tracked owner: ->(controller, model) {controller && controller.current_user} has_many :comments, dependent: :destroy validates :title, presence: true, length: {minimum: 5} end – Alex Cowley Sep 11 '13 at 22:26
  • See updated answer. I may be barking up the tree, but namespacing is always a hassle for me. – smcdrc Sep 12 '13 at 04:50