我不明白爲什麼,如果我寫:attr_accessor和類實例調試
class Building < ActiveRecord::Base
attr_accessor :has_child_custom, 'test'
end
,然後我嘗試用
ap @building
調試它,我不看「has_child_custom」,但如果我輸入:
ap @building.public_methods.grep(/custom/)
我看到了getter和setter方法。
爲什麼會發生這種情況,以及在哪裏可以看到我的自定義屬性?
但我該如何設置默認值? – Costa
我會使用其中一個activerecord生命週期回調。 –
Thx很多,如果需要打印模型或類的所有屬性和方法(如果需要獲取整個視圖),我應該怎麼做? – Costa