简体   繁体   English

在注册期间设计用户名验证

[英]Devise username validation during sign up

I added validation to my user.db and when I try to sign up it doesn't really work. 我在user.db中添加了验证,当我尝试注册时,它并没有真正起作用。 When I don't enter the username, it says that that field can't be blank - which is correct. 当我不输入用户名时,它表示该字段不能为空-这是正确的。 However, if the field is filled in, it still says that the field can't be blank and doesn't allow me to register. 但是,如果填写了该字段,它仍然表示该字段不能为空,并且不允许我注册。 This is my model: 这是我的模型:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :rememberable, :trackable, :validatable

validates :name,
  :presence => true,
  :uniqueness => {
    :case_sensitive => false
  }

  has_many :pins
end

#:recoverable

View 视图

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>

<div align='center'>
    <h2>Sign up</h2><br>



    <div class='field_center'>
        <%= f.input :name %>
        <%= f.input :email %>
        <%= f.input :password %>
        <%= f.input :password_confirmation %>
    </div>

      <div class="form-actions">
        <%= f.submit "Sign Up", class: "btn btn-primary btn-lg" %>
      </div>

    <% end %>
    <br>
    <%= render "devise/shared/links" %>
</div>

Not sure, if it's going to be helpful, but can you please check what parameters are sent at the POST action at the shell running the web server? 不确定是否会有所帮助,但是您能否检查在运行Web服务器的Shell上的POST操作中发送了哪些参数? Make sure the params are sent for :name attribute and they're not empty. 确保为:name属性发送了参数,并且它们不为空。

If the params for name are really empty in web server log, check your view. 如果名称参数在Web服务器日志中确实为空,请检查您的视图。 I had a similar case when a unclosed tag in erb resulted in a weird behavior with Devise (empty params as well). 当erb中的未关闭标签导致Devise出现怪异行为(也为空参数)时,我遇到了类似的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM