对于那些熟悉Devise及其功能的人,您应该具备config / locales目录中Devise.en.yml文件的一些工作知识。此文件在登录时实际上会创建错误消息,即:如果您输入的密码错误,您应该看到错误消息,例如"无效:'无效的电子邮件或密码。"。
在我的情况下,它不起作用,如果我输入错误的用户名/密码没有任何反应,它只是没有登录你,但没有闪存消息。
我的devise.en.yml文件内容都是绿色的,我不确定它是否应该看起来如何,但我有预感,代码可能不对吗?但这可能是也可能不是真正的原因。
不确定要包含哪些控制器或内容,一旦您提出要求,我将立即更新OP。
en:
errors:
messages:
not_found: "not found"
already_confirmed: "was already confirmed"
not_locked: "was not locked"
devise:
failure:
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'You have signed up successfully.'
updated: 'You updated your account successfully.'
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.'
mailer:
confirmation_instructions: 'Confirmation instructions'
reset_password_instructions: 'Reset password instructions'
unlock_instructions: 'Unlock Instructions'
答案 0 :(得分:0)
我猜你必须将此代码添加到app/views/layouts/application.html.erb
:
<% if notice %>
<p class="notice"><%= notice %></p>
<% end %>
<% if alert %>
<p class="alert"><%= alert %></p>
<% end %>
答案 1 :(得分:0)
不确定这是不是真正的问题,而是作为一个想法。
Yaml使用标识作为范围。当你在这里复制粘贴时不确定它是否被破坏了,但如果没有,你的问题可能是你的devise.en.yml文件应该是这样的:
en:
errors:
messages:
not_found: "not found"
...
devise:
failure:
...
而不是你现在的问题。另外,请检查您是否使用空格,而不是标识符。