问题
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