Public_Activity returning an object instead of result

半世苍凉 提交于 2020-01-07 02:58:06

问题


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:


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


来源:https://stackoverflow.com/questions/18747867/public-activity-returning-an-object-instead-of-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!