關於belongs_to
關係有可能做關聯擴展嗎?belongsrec關於活躍記錄的關聯擴展
我試圖做到這一點使用一個模塊,但保留被告知我打電話的方法是私有的:
module TestExtension
def test
puts 'test successful'
end
end
class Question < ActiveRecord::Base
belongs_to :user, extend: TestExtension
end
我每次運行它雖然抱怨說,該方法是私有
q = Question.first
q.test
# => NoMethodError: Attempt to call private method `test'
我不完全清楚是否有可能在belongs_to上進行AR擴展。它在Rails 3.0.7上工作正常,但現在在3.1.0中失敗
你把模塊TestExtension放在哪裏?在lib目錄中的新文件中? – Coderama