1
我新的軌道,並閱讀一些Rails代碼:https://github.com/discourse/discourse/blob/master/app/models/user_action_observer.rb#L1從軌道觀察者的這段代碼中我們可以知道什麼?
class UserActionObserver < ActiveRecord::Observer
observe :post_action, :topic, :post, :notification, :topic_user
def after_save(model)
puts 'do something'
end
end
我們可以知道,從這個代碼?例如
- 因爲它的名字是
UserActionObserver
,所以它是一個觀察者模型UserAction
? - 它觀察到:
:post_action, :topic, :post, :notification, :topic_user
,這些字段是什麼意思?將被創建或只是對其他模型的某些字段的一些引用? - 什麼時候會調用方法
after_save
,什麼是model
參數?
' :post_action'表示文件'post_action.rb'或者它將被翻譯成類名'PostAction'? – Freewind 2013-03-04 05:13:09
請看更新後的答案:) – jvnill 2013-03-04 05:25:09