[英]Is there any possibility to control model callback for only one controller method call?
i need to use model callback when only selected action in controller 当仅在控制器中选择动作时,我需要使用模型回调
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
is there any possibilities 有没有可能
You can get detailed information in below link 您可以在下面的链接中获取详细信息
http://www.gsubbarao.com/2012/11/ruby-on-rails-3x-skip-callback-and.html http://www.gsubbarao.com/2012/11/ruby-on-rails-3x-skip-callback-and.html
这应该在测试模型(app / models / test.rb)中起作用:
skip_callback(:find, :after, :review_exam)
You can't do this magically: the model has no concept of who is calling it, so it can't change its behaviour based on the current controller action. 您无法神奇地做到这一点:模型不知道调用它的人的概念,因此它无法基于当前的控制器操作来更改其行为。
You'd be better off having a controller before_filter
that calls include_load_question_module
on the relevant instances. 您最好在相关实例上使用一个控制器before_filter
来调用include_load_question_module
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.