[英]Is there any possibility to control model callback for only one controller method call?
當僅在控制器中選擇動作時,我需要使用模型回調
class TestController
def end_exam(); end
def resume_exam(); end
def continue_exam(); end
def review_exam(); end
end
class Test //Model
after_find :include_load_question_module // only for end_exam, resume, continue
end // not for review_exam
有沒有可能
這應該在測試模型(app / models / test.rb)中起作用:
skip_callback(:find, :after, :review_exam)
您無法神奇地做到這一點:模型不知道調用它的人的概念,因此它無法基於當前的控制器操作來更改其行為。
您最好在相關實例上使用一個控制器before_filter
來調用include_load_question_module
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.