1

对于那些熟悉 Devise 及其功能的人,您应该对 config/locales 目录中的 Devise.en.yml 文件有一些工作知识。该文件本质上在登录时会创建错误消息,即:如果您输入的密码错误,您应该会看到类似“invalid: 'Invalid email or password.”这样的错误消息。

在我的情况下,它不起作用,如果我输入错误的用户名/密码,什么也不会发生,它只是不会让您登录,但没有闪烁消息。

我的 devise.en.yml 文件内容都是绿色的,我不确定这是否应该是这样的,但我有一种预感,代码可能有问题?但这可能是也可能不是真正的原因。

不确定要包含哪些控制器或内容,因此一旦您提出要求,我将使用它们更新 OP。

这是我的应用程序的 devise.en.yml 文件:

  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'
4

2 回答 2

0

我猜你必须将此代码添加到app/views/layouts/application.html.erb

  <% if notice %>
    <p class="notice"><%= notice %></p>
  <% end %>

  <% if alert %>
    <p class="alert"><%= alert %></p>
  <% end %>
于 2013-02-27T20:40:52.170 回答
0

不确定这是否是真正的问题,但作为一个想法。

Yaml 使用标识来确定范围。不确定当您在此处复制粘贴时它是否损坏,但如果没有,您的问题可能是您的 devise.en.yml 文件应该如下所示:

en:
  errors: 
    messages:
      not_found: "not found"
      ...
  devise:
    failure:
       ...

而不是它现在在你的问题中的样子。此外,请检查您是否使用空格,而不是制表符进行标识。

于 2013-02-27T21:07:41.937 回答