2

因此,我正在尝试使用 Public Activity gem 作为通知时间线,但我不明白为什么会收到 NameError ,即未初始化的常量消息。这是我得到的错误:

NameError in ActivitiesController#index
uninitialized constant ActivitiesController::PublicActivity

app/controllers/activities_controller.rb:3:in `index'

未初始化的常量ActivitiesController::PublicActivity

这是我的控制器代码,据说错误是:

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

我正在尝试基于 Rails 演员:http ://railscasts.com/episodes/406-public-activity 据我所知,我已经做了与上面相同的事情。

没有任何活动模型,但这是我使用 PublicActivity 模块的帖子和评论模型:

后模型:

class Post < ActiveRecord::Base
  include PublicActivity::Model
  tracked

评论模型

class Comment < ActiveRecord::Base
    include PublicActivity::Model
tracked

belongs_to :post
belongs_to :user
end
4

1 回答 1

1

根据宝石来源

 def load_orm
      require "public_activity/orm/#{@@orm.to_s}"
      m = "PublicActivity::ORM::#{@@orm.to_s.classify}".constantize
      ::PublicActivity.const_set(:Activity,  m.const_get(:Activity))
      ::PublicActivity.const_set(:Adapter,   m.const_get(:Adapter))
      ::PublicActivity.const_set(:Activist,  m.const_get(:Activist))
      ::PublicActivity.const_set(:Trackable, m.const_get(:Trackable))
    end

您应该使用下一个代码

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

还要确保您使用 bundle 安装了 gem,检查bundle show public_activity

于 2013-03-20T22:00:28.780 回答