0

我按照 railscasts 教程安装了 public_activity gem。浏览器中的活动页面正在返回一个对象,而不是活动所引用的实际事件。

class ActivitiesController < ApplicationController

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

负责创建包含活动的表的迁移:

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
4

1 回答 1

0

你有没有试过这个看看它是否有效:

Activity.order("created_at desc")

我只是想知道您是否正确设置了命名空间。

我不熟悉您尝试命名空间的方式。也许试试这个:

Module PublicActivity
 class Activity

 end
end

或者

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

 end
于 2013-09-11T18:09:31.017 回答