当我使用i18n时,我的Flash消息不显示,而当我仅使用字符串时,它却显示。这是在应用程序控制器中。
这有效:
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
这什么都不显示:
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
我尝试仅使用t
而不是I18n.t
,但也没有任何效果。
使用pry
并运行I18n.t
时,它将显示预期的字符串。
i18n文件:
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.'
我在做什么错了?