You could define the current_user
method yourself. It could, for example, go in ApplicationController
:
def current_user
if current_candidate # You could use candidate_signed_in? instead.
current_candidate
else
current_employer
end
end
Then it should be available in all your controllers and will be used by CanCan's current_ability
method. If you want it available in views too, one option is to then add the line helper_method :current_user
to ApplicationController
.
Another option is to override the CanCan current_ability
method to give the same effect as the above code by adding this to your ApplicationController
:
def current_ability
@current_ability ||= ::Ability.new((candidate_signed_in?) ? currrent_candidate : current_employer)
end