9

我有以下从 Entry 模型继承的 mongoid 模型:

class Entry::Twitter < Entry

  field :retweet_count, :type => Integer, :default => 0
  field :retweeted, :type => Boolean, :default => false
  field :favorited, :type => Boolean, :default => false

  # in_reply_to_screen_name, in_reply_to_status_id_str, in_reply_to_user_id_str
  field :reply, :type => Hash

  field :from, :type => Hash # user: id_str, name, screen_name
  field :time, :type => Time # created_at
  field :data, :type => Hash # entities (hashtags and user_mentions)
  field :assets, :type => Hash # urls from original entities
  field :service, :type => String, :default => "twitter"

  attr_accessible :assets

  # validations
  validates_presence_of :retweet_count, :from, :time, :data

  # override set_service cause of https://github.com/sferik/twitter/issues/303

  def set_service
    self.service = "twitter"
  end
end

当我尝试引用它时,我收到以下警告:

ruby-1.9.3-p125 :001 > Entry::Twitter
(irb):1: warning: toplevel constant Twitter referenced by Entry::Twitter
=> Twitter

它没有引用我的模型,而是引用了由 gem 定义的顶级常量 Twitter。

我能做些什么来解决这个问题?我不想为我的班级使用另一个名字。

4

1 回答 1

5

这是解决方案: https ://github.com/rails/rails/issues/6931

我刚刚添加require_dependency 'entry/twitter'到每个引用的文件Entry::Twitter以避免这个问题,现在它工作正常。

于 2012-10-18T17:40:40.730 回答