3

我有一个看起来像这样的类:

class Refinery::Blog::Post < ActiveRecord::Base
  belongs_to :author, class_name: '::Refinery::User', foreign_key: :user_id

  # SNIP very long class body
end

如果我能提供帮助,我不想覆盖整个类,因为那里有很多行为应该保持不变,并且引擎的许多其他部分按名称引用该类,所以我不能子类化它。有什么方法可以class_eval用来删除或替换现有的关联?我试着像这样重新定义它:

Refinery::Base::Post.class_eval do
  belongs_to :author, class_name: 'MyUser', foreign_key: :user_id
end

但它似乎不起作用。

4

1 回答 1

0

查看初始化文件,我认为它在 config/initializers/refinery/blog.rb

Refinery::Blog.configure do |config|


  # If you're grafting onto an existing app, change this to your User class
   Refinery::Blog.user_class = 'MyUser'
end
于 2013-07-24T21:09:27.297 回答