2011-02-10 42 views
1

插件提供了一個名爲User的模型。是否有可能在我的應用程序中重新打開它?在主Rails應用程序中重新打開插件模型

如果我創建app/models/user.rb並在那裏嘗試,整個模型將被覆蓋,原始插件方法不再可用。

+0

你如何重新打開用戶類? (在app/models/user.rb中) – 2011-02-10 17:52:45

回答

1

這是我迄今發現的唯一途徑:

# app/models/plugin_user.rb 
class PluginUser 
    def self.load 
    User.class_eval do 
     # my code here 
    end 
    end 
end 

# plugin model: 
class User 
    # ... 
end 

PluginUser.load 

,如果有這樣無需修改插件代碼的方式這將是很好。在這種情況下,它並不重要,因爲插件是我的,但如果我需要對另一個插件執行相同的操作,則需要將其插入。

相關問題