为什么设计错误不会在注册页面上显示?

时间:2017-04-17 13:56:45

标签: ruby-on-rails devise

我无法显示设计错误。问题仅发生在注册页面中。但登录和注册的配置是相同的...... 我通过application.html.erb

显示错误

我知道错误是正确生成的,因为当我将resource.errors.full_messages放在开头时,会显示错误。但没有我的风格。

注册

.section
  .subscribe-c.w-container
    .section-title-group
      h2.heading Bonjour !
    = simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
      = f.input_field :email, class: "form-field w-input", placeholder: "Email"
      = f.input_field :password, class: "form-field w-input", placeholder: "Mot de passe", html: { autocomplete: 'off' }
      = f.input_field :password_confirmation, class: "form-field w-input", placeholder: "Confirmez votre mot de passe", html: { autocomplete: 'off' }
      = f.submit "Je m'inscris", class: "button full-width w-button"
      = render "devise/shared/links"

enter image description here

登录(正常工作的人)

.section
  .subscribe-c.w-container
    .section-title-group
      h2.heading Bonjour !
    = simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
      = f.input_field :email, class: "form-field w-input", placeholder: "Email"
      = f.input_field :password, class: "form-field w-input", placeholder: "Mot de passe", html: { autocomplete: 'off' }
      = f.submit "c'est parti !", class: "button full-width w-button"
      = render "devise/shared/links"

enter image description here

application.html.erb

  <body class=body>
    <% if notice %>
      <p class="alert alert-success"><%= notice %></p>
    <% end %>
    <% if alert %>
      <p class="alert alert-danger"><%= alert %></p>
    <% end %>
    <%= render 'layouts/navbar' %>
    <%= yield %>
 </body>

2 个答案:

答案 0 :(得分:0)

这是因为您正在使用f.input_field告诉simpleform去除表单字段周围的所有div。如果切换到f.input,simpleform会将您的字段包装在Rails看起来要添加错误消息的div中。这可能会破坏您的一些样式,因为现在所有表单字段都有一个额外的div包装器,但您始终可以在表单顶部创建自己的自定义错误消息。实施例

<% if @some_object.errors.any? %>
  <ul>
     <% @some_object.errors.each do |error,msg| %>
        <li> <%=error.capitalize%>  <%=msg%></li>
     <% end %>
  </ul>
<% end %>

答案 1 :(得分:0)

似乎缺少正确的翻译:{{1​​}}。

以下是Devise所有法语翻译的列表:https://github.com/plataformatec/devise/wiki/I18n#french-devisefryml

确保根据顶部的文档正确设置配置。

此外,如果您正在寻找特定的"Courriel translation missing: fr.activerecord.errors.models.user.attributes.email.blank翻译,您可以查看rails-i18n gem,在那里您可以找到更多法语翻译here

相关问题