In my application_contorller I have the method:
def authorize(message = "Please Login")
if current_user.nil?
redirect_to :root, alert: message
return
end
end
And I want to be able to put a custom message in if needed so that I can call this method from many different controllers in a before_filter.
For example in another controller I have:
before_filter :authorize, except: [:index,:show]
How can I pass the message param into the :authorize method call in the before_filter in order to show a different message?
There isn't a way to pass parameters to a request callback when you define it using a symbol. You can instead use a block:
before_filter(only: [:index, :show]) { authorize('You forgot to login') }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With