Filters 将controller中重复的代码抽出来
before_filter 在controller 中可以在调用该函数前调用。
after_filter, 函数运行完成之后才会调用,但是重定向之类的代码就不支持抽出来了
类似
,否则会报错
如果调用了,就找不到返回的页面
after_filer ,函数应该 操作日志记录,这类的业务功能中 才会有用
before_filter 在controller 中可以在调用该函数前调用。
after_filter, 函数运行完成之后才会调用,但是重定向之类的代码就不支持抽出来了
类似
redirect_to
,否则会报错
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
如果调用了,就找不到返回的页面
after_filer ,函数应该 操作日志记录,这类的业务功能中 才会有用