gpt4 book ai didi

html - 设计错误验证不适用于登录

转载 作者:行者123 更新时间:2023-12-03 08:50:13 27 4
gpt4 key购买 nike

我正在使用devise进行登录和注册等。我的验证似乎可以在sign-up页面上使用,但不能在sign-in页面上使用。这是我正在使用的。

session/new.html.erb

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>

<%= render 'shared/devisemes' %>
<div class="form-group">
<%= f.email_field :email, autofocus: true, :class => 'form-control', :placeholder => "Email" %>
</div>

<div class="form-group">
<%= f.password_field :password, :autocomplete => :off, :class => 'form-control', :placeholder => "Password" %>
</div>

<% if devise_mapping.rememberable? -%>
<div class="form-group">
<%= f.check_box :remember_me %> Remember Me
</div>
<% end -%>

<div class="actions">
<%= f.submit "Log in", :class => "btn btn-primary" %>
<% link_to "Forget Password", new_user_password_path, :class => "btn btn-primary" %>
</div>
<% end %>

shared/_devisemes.html.erb

<% unless resource.errors.empty? %> 

<script type="text/javascript">
<% resource.errors.full_messages.each do |msg| %>
toastr.error("<%= msg %>")
<% end %>
</script>
<% end %>


user.rb

  validates :username, :presence => true, length: { minimum: 4, maximum: 16 }, :uniqueness => { :case_sensitive => false }
validates :email, :presence => true, length: { minimum: 6, maximum:45 }, :uniqueness => { :case_sensitive => false}



validates_format_of :username, with: /^[a-zA-Z0-9_\.]*$/, :multiline => true

当我单击提交时,其空白或与用户名不匹配时,它将重新加载页面没有错误。

最佳答案

尝试在末尾添加以下代码:

<% if flash[:notice].present? %>
<p><%= flash[:notice] %></p>
<% end %>

<% if flash[:alert].present? %>
<p><%= flash[:alert] %></p>
<% end %>

另外,您是否尝试过简单的html验证?喜欢 <%= f.email_field :email, autofocus: true, :class => 'form-control', :placeholder => "Email", required =“true” %> 或者其他的东西

关于html - 设计错误验证不适用于登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43085865/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com