1
我的嘗試看起來像這樣,具有繼承性的非主動記錄模型。 app/models/matching_method.rb
:Rails 4中的非主動記錄模型結構
class MatchingMethod
attr_accessor :name
end
class LD < MatchingMethod
end
class Soundex < MatchingMethod
end
通過這個我可以受益於使用MatchingMethod.descendants
。 這工作得很好。所以我試圖將每個課程移到自己的文件夾中。
models/
- concern/
+ matching_method/
- ld.rb
- soundex.rb
- matching_method.rb
併爲每個類:
class MatchingMethod::LD < MatchingMethod
end
不過,這一次MatchingMethod.descendants
找不到 繼承的類了。
有什麼建議嗎?或者我應該重新設計這種方法。謝謝!
謝謝!有沒有辦法自動加載這些後代方法? – 2015-04-02 15:09:06
@PhatWangrungarun yes,Dir ['app/models/matching_method/*。rb']。each {| f | 需要Pathname.new(f).realpath} – 2015-04-02 15:12:30
這很好,謝謝!但是,每次我在後代類中進行一些更改時,我都需要重新啓動應用程序才能獲得更改。這是正常的嗎? – 2015-04-02 17:21:06