ruby-on-railsruby

Why there is no double-render when using before_action?


I am wondering why there is no double-render when there is a redirect_to or render in before_action. Consider this example:

class SomeController < ApplicationController
 before_action :callback

 def new
  callback2
  render 'new'
 end

 def callback
  render 'new'
 end

 def callback2
  render 'new'
 end

end

I see that before_action will be useless if it can't redirect but how it is made? If I comment the before_action it will throw exception. How is before_action implemented to not cause double-render?


Solution

  • See the Rails Guide on controllers :

    If a "before" filter renders or redirects, the action will not run. If there are additional filters scheduled to run after that filter, they are also cancelled.