【问题标题】:How can i custom confirmation messages of Devise using Bootstrap alerts?如何使用 Bootstrap 警报自定义设计的确认消息?
【发布时间】:2018-06-14 09:33:21
【问题描述】:

对于确认消息,我指的是登录后显示为示例并显示“访问成功!”的消息。我已经自定义了 devise_errors_messages 但我没有找到确认消息...请帮助我!

这是帮手:

module DeviseHelper
  def devise_error_messages!
    return '' if resource.errors.empty?

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
    html = <<-HTML

    <div class="alert alert-error alert-danger"> <button type="button"
    class="close" data-dismiss="alert">×</button>
      #{messages}
    </div>
    HTML

    html.html_safe
  end
end 

...我想编辑这些消息:

en:
  devise:
    confirmations:
      confirmed: "Your email address has been successfully confirmed."
      send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
      send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
    failure:
      already_authenticated: "You are already signed in."
      inactive: "Your account is not activated yet."
      invalid: "Invalid %{authentication_keys} or password."
      locked: "Your account is locked."
      last_attempt: "You have one more attempt before your account is locked."
      not_found_in_database: "Invalid %{authentication_keys} or password."
      timeout: "Your session expired. Please sign in again to continue."
      unauthenticated: "You need to sign in or sign up before continuing."
      unconfirmed: "You have to confirm your email address before continuing."
    mailer:
      confirmation_instructions:
        subject: "Confirmation instructions"
      reset_password_instructions:
        subject: "Reset password instructions"
      unlock_instructions:
        subject: "Unlock instructions"
      email_changed:
        subject: "Email Changed"
      password_change:
        subject: "Password Changed"
    omniauth_callbacks:
      failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
      success: "Successfully authenticated from %{kind} account."
    passwords:
      no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
      send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
      send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
      updated: "Your password has been changed successfully. You are now signed in."
      updated_not_active: "Your password has been changed successfully."
    registrations:
      destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
      signed_up: "Welcome! You have signed up successfully."
      signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
      signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
      signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
      update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
      updated: "Your account has been updated successfully."

【问题讨论】:

  • I have already custom the devise_errors_messages - 然后将它们放在您的问题中向我们展示。
  • 它们在devise.en.yml 文件中
  • 它们不在同一个位置... devise_errors_messages 在 devise_helper 中,我可以自定义它们的布局,但确认消息在哪里?我必须添加一些东西吗?
  • 您的意思是您无法看到视图中的变化?
  • 我的意思是设计的正常消息不会出现在引导布局中。我可以自定义错误消息,因为它们在 DeviseHelper 中,但其他消息没有。当我进行注册时,闪烁消息“欢迎!您已注册成功。”显示为白色,而不是绿色。

标签: ruby-on-rails twitter-bootstrap devise ruby-on-rails-5


【解决方案1】:

我在我的views/layouts/application.html.erb 中使用这个_flashes.html.erb 也许这可以帮助面临同样问题的人

<div id="message">
    <% if notice %>
      <div  id="inner-message-success" class="alert alert-success" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <%= notice %>
      </div>
    <% end %>
    <% if alert %>
      <div  id="inner-message-danger" class="alert alert-danger" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <%= alert %>
      </div>
    <% end %>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 2013-05-18
    • 2018-09-04
    • 2020-02-18
    相关资源
    最近更新 更多