I've a controller concern which regroup the logic for access control:
module AccessControl
extend ActiveSupport::Concern
def restrict
unless current_user
flash.now[:danger] = 'You must log in first'
redirect_to :root
end
end
end
which is included in some controllers and used as before_action
filter
class SomeController < ApplicationController
include AccessControl
before_action :restrict
end
But somehow the flash message is not showing up (other flash messages are properly displayed if they're called from Controllers).
Any idea about why I can't call a flash message from a Concern ? If it's not the expected/recommended implementation, how could I've DRY controllers but still have flash messages displayed ?
Haven't found the answer inside ActiveSupport::Concern's nor ActiveDispach::Flash's documentation. I'm trying some alternatives but none of them are actually working.