0
類
我想內添加非自軌方法
class User < ActiveRecord::Base
def global_user_id
User.find_by_username("Global_User").id
end
end
返回當前的全球用戶ID的方法。我希望它使用User.global_user_id
運行,而不是像User.new.global_user_id
我該怎麼做?
我需要在其他模型的用戶ID,現在它卡在我認爲是最好的地方的類資源。
謝謝!現在所有回到我身邊......作爲一個旁註,我想我可以做def global_user_id
Tallboy
在這種情況下,您在方法調用中不需要'User.',因爲您已經在正確的範圍內。 –
@安德魯:是的,你說得對。 – Matzi