Public_Activity返回一个对象而不是结果 [英] Public_Activity returning an object instead of result
本文介绍了Public_Activity返回一个对象而不是结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在railscasts教程之后安装了public_activity gem.浏览器中的活动页面正在返回一个对象,而不是该活动所引用的实际事件.
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
推荐答案
您是否尝试过查看它是否有效:
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
或
class PublicActivity::Activity < ActiveRecord::Base (or whatever class you want)
end
这篇关于Public_Activity返回一个对象而不是结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文