新手问题 Devise 提交验证不错,不知这是哪个 Gem 搞的鬼

syutran · March 14, 2018 · Last by syutran replied at March 14, 2018 · 1300 hits

使用 devise 作为系统认证,前几天还能使用注册,今天就不行了。

输上邮箱,密码和二次确认的密码,注册报错。 如图:

后台显示的信息:

Started POST "/users" for 192.168.1.211 at 2018-03-14 13:57:43 +0800
Cannot render console from 192.168.1.211! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"zlK5i56uk0NdvVy6AEctGhGpnaVyE6GhgNCINTQwwG5WfpxY9WPvEWtanHENl9XVyZGRXXV0GQcACB3wcEMpHQ==", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
   (0.2ms)  BEGIN
  User Exists (0.4ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY '[email protected]' LIMIT 1
   (0.2ms)  ROLLBACK
  Rendering devise/registrations/new.html.erb within layouts/application
  Rendered devise/shared/_links.html.erb (1.1ms)
  Rendered devise/registrations/new.html.erb within layouts/application (8.2ms)
  Rendered layouts/_header.html.erb (2.3ms)
  Rendered comments/_flashes.html.erb (0.5ms)
  Rendered layouts/_footer.html.erb (0.3ms)
Completed 200 OK in 331ms (Views: 90.9ms | ActiveRecord: 0.8ms)

在网上查一那串报错信息:Please review the problems below:

好像是 simple_form 的报错信息,但再无其它资料表明原因。 各位给想想~

执行rails generate simple_form:install 试试,好像 simple_form 的一个 bug,升级版本后原有 simple_form 配置文件就错乱了。表单验证对也报错。

教你一个调试方法:

$ bundle open devise

在编辑器里面找到 app/controllers/devise/registrations_controller.rb

def create
  # 末尾增加 puts 将 resource 打印出来,就能看到错误信息了
  puts resource.inspect
end

或者你可以用 rails g devise:views 命令,生成出 Devise 的 views,并修改 devise/registrations/new.html.erb

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <% if resource.errors.any? %>
  <ul>
    <% resource.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
  </ul>
  <% end %>

@zhufenggood 兄台的方法没解决; @huachuang 华兄的方法找出的问题所在,原来是关联搞的鬼~ thank you ~

huacnlee closed this topic. 14 Mar 14:44
You need to Sign in before reply, if you don't have an account, please Sign up first.