My flash message doesn't show when I use i18n, but does when I just use a string. This is in the application controller.
This works:
def user_not_authorized(exception)
policy_name = exception.policy.class.to_s.underscore
## require 'pry'; binding.pry
flash[:alert] = "You're not invited for this event."
redirect_to request.referrer || root_path
end
This doesn't show anything:
def user_not_authorized(exception)
policy_name = exception.policy.class.to_s.underscore
## require 'pry'; binding.pry
flash[:error] = I18n.t "#{policy_name}.#{exception.query}", scope: 'pundit',
default: [:default, "I'm sorry, you're not allowed"]
redirect_to request.referrer || root_path
end
I tried using just t
instead of I18n.t
but no effect either.
When using pry
and running the I18n.t
it shows the expected String.
The i18n file:
pundit:
default: "I'm sorry, but you're not allowed to see this."
event_policy:
show?: 'You cannot view this event. You need an invitation first.'
What am I doing wrong?