Public_Activity returning an object instead of result

135 Views Asked by At

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
1

There are 1 best solutions below

4
On

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