In Rails, if "before_filter :login_required" works, then why will adding "login_required" to an action not work? -


if using

before_filter :login_required 

works, actions of controller, if comment line out, , so:

def index   login_required     [...] end 

then server complains can render or redirect once per action. thought using before filter same adding method above. please explain.

before_filter , around_filter may halt request before controller action run. useful, example, deny access unauthenticated users or redirect http https. call render or redirect. after filters not executed if filter chain halted.

this rails api(filter chain halting). so, if in filter, if render or redirect happens, filter chain halts , rest code not executed. so, error not happen in case. when call method directly, code after method call executed , therefore, error 'render or redirect once per action' happens.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -