can anyone tell me how before filter can call the private method audit
which from the parent class ?
because the bank controller has a private method called audit, this one
should not be inheritance by VaultController, so how the before_filter
use the private method audit ?
if the child class can use the parent class private method . does it
break encapsulation ? does the private has any sense here .because you
can use it from ur child class , why just make it public ?
below is the example from rail api.
Controller inheritance hierarchies share filters downwards, but
subclasses can also add or skip filters without affecting the
superclass. For example:
class BankController < ActionController::Base
private def audit # record the action and parameters in an audit log end
class VaultController < BankController
private def verify_credentials # make sure the user is allowed into the vault end
Now any actions performed on the BankController will have the audit
method called before. On the VaultController, first the audit method is
called, then the verify_credentials method. If the audit method renders
or redirects, then verify_credentials and the intended action are never