Ruby on rails Rails设计不写入DB的参数(仅在服务器上)

Ruby on rails Rails设计不写入DB的参数(仅在服务器上),ruby-on-rails,devise,Ruby On Rails,Devise,我正在维护一个大约有2年历史的Rails应用程序。在过去的几个月里,用户在尝试创建新用户帐户时报告了错误(以前没有问题)。通过查看日志,我发现创建Desive用户帐户时没有电子邮件地址和用户名。这是不可能的,因为这两个字段都是必填字段。电子邮件是用户的唯一标识符,因此这显然会破坏各种各样的功能 我在当地进行了测试,无法重现该问题。然后我在服务器上测试了它——在那里,我可以在日志中看到,当创建用户时,插入中不包括这两个参数 本地 Processing by RegistrationsControl

我正在维护一个大约有2年历史的Rails应用程序。在过去的几个月里,用户在尝试创建新用户帐户时报告了错误(以前没有问题)。通过查看日志,我发现创建Desive用户帐户时没有电子邮件地址和用户名。这是不可能的,因为这两个字段都是必填字段。电子邮件是用户的唯一标识符,因此这显然会破坏各种各样的功能

我在当地进行了测试,无法重现该问题。然后我在服务器上测试了它——在那里,我可以在日志中看到,当创建用户时,插入中不包括这两个参数

本地

Processing by RegistrationsController#create as HTML
 Parameters: {"utf8"=>"✓", "authenticity_token"=>"0JW4oOs+D9plubsIxDxO2N8RjiQtCpuSNE92hJqCQ/N6QkYTFPqnSxmSeqhiKBFFySCzRgG3L+TbQJKZCF9zmQ==", "user"=>{"username"=>"jantesting1", "email"=>"jantesting1@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "team_code"=>"cat45", "num_team_members"=>"0", "accept_terms"=>"1"}, "commit"=>"Sign up"}
##### current_user does not exist #####
 Team Exists (0.4ms)  SELECT  1 AS one FROM `teams` WHERE `teams`.`code` = 'cat45' LIMIT 1
 ↳ app/controllers/registrations_controller.rb:4
  (0.2ms)  BEGIN
 ↳ app/controllers/registrations_controller.rb:5
 User Exists (1.5ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY 'jantesting1@gmail.com' LIMIT 1
 ↳ app/controllers/registrations_controller.rb:5
 User Create (0.6ms)  INSERT INTO `users` (`email`, `encrypted_password`, `created_at`, `updated_at`, `username`) VALUES ('jantesting1@gmail.com', '$2a$11$TiHmwBmI/FmcSXk.ypKu2esrr9nKGoEpjiDPaxQanlD7n6ZQx3/T2', '2020-01-29 18:05:22', '2020-01-29 18:05:22', 'jantesting1')
 ↳ app/controllers/registrations_controller.rb:5
  (0.3ms)  COMMIT
class User < ApplicationRecord
  belongs_to :team, optional: true
  has_many :readiness_factor_responses, dependent: :destroy
  has_many :user_sessions, dependent: :destroy
  has_many :activity_plan_users, dependent: :destroy

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :username,
    presence: true,
    length: { minimum: 2 }

  attr_accessor :team_code
  attr_accessor :num_team_members
  attr_accessor :accept_terms


  def is_admin?
    self.admin
  end

  def step_and_substep
    [self.current_step, self.current_substep]
  end

  def current_session
    # weak way to handle the case where other teammates have signed up but not logged in
    if self.user_sessions
      self.user_sessions.order("created_at").last
    else
      nil
    end
  end

  # user is defined as idle if they haven't taken an action in 30 min. They will also be forced to reauth by devise
  def is_idle?
    if self.current_session && self.current_session.last_action_time
      (Time.now - self.current_session.last_action_time) > 1800
    end
  end

end
服务器

Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"LrjPR95LZzIEFQH5PEWpkX0GI/q4xnJp+UVmT5gcjbxlbH8IsBbETL0l7xg5w6c33dx7yBZ1ztQVhpvigDjjgg==", "user"=>{"username"=>"jantesting1", "email"=>"jantesting1@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "team_code"=>"yak44", "num_team_members"=>"3", "accept_terms"=>"1"}, "commit"=>"Sign up"}
##### current_user does not exist #####
  Team Exists (0.5ms)  SELECT  1 AS one FROM `teams` WHERE `teams`.`code` = 'yak44' LIMIT 1
   (0.2ms)  BEGIN
  User Exists (0.3ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY 'jantesting1@gmail.com' LIMIT 1
  User Create (0.2ms)  INSERT INTO `users` (`encrypted_password`, `created_at`, `updated_at`) VALUES ('$2a$11$3MBvOEWhpb7IhoH8tl7YXemCZHWxea0FA/b8Ww90m3oEx.hYFJwuK', '2020-01-30 12:21:45', '2020-01-30 12:21:45')
   (2.1ms)  COMMIT
    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :username, :password, :password_confirmation, :remember_me, :team_code, :num_team_members, :accept_terms])
      devise_parameter_sanitizer.permit(:sign_in, keys: [:login, :email, :password, :remember_me, :num_team_members])
      devise_parameter_sanitizer.permit(:account_update, keys: [:email, :password, :password_confirmation, :current_password])
    end
class RegistrationsController < Devise::RegistrationsController

  def create
    if Team.where(code: params[:user][:team_code]).exists?
      super
      if current_user
        current_user.team = Team.find_by_code(params[:user][:team_code])
        current_user.save!
      end
    else
      redirect_to new_user_registration_path, :flash => { :error => "Team code invalid" }
    end
  end

  protected
    def after_sign_up_path_for(resource)
      UserSession.create(user_id: current_user.id, login_time: DateTime.now, last_action_time: DateTime.now, num_team_members: params[:user][:num_team_members])

      root_path
    end
end
而且,据我所知,这个问题最近开始出现,代码库没有任何变化。我已经检查过这两个都是相同的git状态,所有相关的库都是相同的版本(无论如何,它大部分都在Gemfile中),等等。我已经用git检查过一个旧版本的代码,问题仍然存在

最后,也许是最令人困惑的是,一些用户在过去几周内已经能够创建帐户(即电子邮件不是空白的)。但不是大多数。而不是我

关于去哪里看有什么建议吗

应用程序\u控制器

Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"LrjPR95LZzIEFQH5PEWpkX0GI/q4xnJp+UVmT5gcjbxlbH8IsBbETL0l7xg5w6c33dx7yBZ1ztQVhpvigDjjgg==", "user"=>{"username"=>"jantesting1", "email"=>"jantesting1@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "team_code"=>"yak44", "num_team_members"=>"3", "accept_terms"=>"1"}, "commit"=>"Sign up"}
##### current_user does not exist #####
  Team Exists (0.5ms)  SELECT  1 AS one FROM `teams` WHERE `teams`.`code` = 'yak44' LIMIT 1
   (0.2ms)  BEGIN
  User Exists (0.3ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY 'jantesting1@gmail.com' LIMIT 1
  User Create (0.2ms)  INSERT INTO `users` (`encrypted_password`, `created_at`, `updated_at`) VALUES ('$2a$11$3MBvOEWhpb7IhoH8tl7YXemCZHWxea0FA/b8Ww90m3oEx.hYFJwuK', '2020-01-30 12:21:45', '2020-01-30 12:21:45')
   (2.1ms)  COMMIT
    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :username, :password, :password_confirmation, :remember_me, :team_code, :num_team_members, :accept_terms])
      devise_parameter_sanitizer.permit(:sign_in, keys: [:login, :email, :password, :remember_me, :num_team_members])
      devise_parameter_sanitizer.permit(:account_update, keys: [:email, :password, :password_confirmation, :current_password])
    end
class RegistrationsController < Devise::RegistrationsController

  def create
    if Team.where(code: params[:user][:team_code]).exists?
      super
      if current_user
        current_user.team = Team.find_by_code(params[:user][:team_code])
        current_user.save!
      end
    else
      redirect_to new_user_registration_path, :flash => { :error => "Team code invalid" }
    end
  end

  protected
    def after_sign_up_path_for(resource)
      UserSession.create(user_id: current_user.id, login_time: DateTime.now, last_action_time: DateTime.now, num_team_members: params[:user][:num_team_members])

      root_path
    end
end
注册\u控制器

Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"LrjPR95LZzIEFQH5PEWpkX0GI/q4xnJp+UVmT5gcjbxlbH8IsBbETL0l7xg5w6c33dx7yBZ1ztQVhpvigDjjgg==", "user"=>{"username"=>"jantesting1", "email"=>"jantesting1@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "team_code"=>"yak44", "num_team_members"=>"3", "accept_terms"=>"1"}, "commit"=>"Sign up"}
##### current_user does not exist #####
  Team Exists (0.5ms)  SELECT  1 AS one FROM `teams` WHERE `teams`.`code` = 'yak44' LIMIT 1
   (0.2ms)  BEGIN
  User Exists (0.3ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY 'jantesting1@gmail.com' LIMIT 1
  User Create (0.2ms)  INSERT INTO `users` (`encrypted_password`, `created_at`, `updated_at`) VALUES ('$2a$11$3MBvOEWhpb7IhoH8tl7YXemCZHWxea0FA/b8Ww90m3oEx.hYFJwuK', '2020-01-30 12:21:45', '2020-01-30 12:21:45')
   (2.1ms)  COMMIT
    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :username, :password, :password_confirmation, :remember_me, :team_code, :num_team_members, :accept_terms])
      devise_parameter_sanitizer.permit(:sign_in, keys: [:login, :email, :password, :remember_me, :num_team_members])
      devise_parameter_sanitizer.permit(:account_update, keys: [:email, :password, :password_confirmation, :current_password])
    end
class RegistrationsController < Devise::RegistrationsController

  def create
    if Team.where(code: params[:user][:team_code]).exists?
      super
      if current_user
        current_user.team = Team.find_by_code(params[:user][:team_code])
        current_user.save!
      end
    else
      redirect_to new_user_registration_path, :flash => { :error => "Team code invalid" }
    end
  end

  protected
    def after_sign_up_path_for(resource)
      UserSession.create(user_id: current_user.id, login_time: DateTime.now, last_action_time: DateTime.now, num_team_members: params[:user][:num_team_members])

      root_path
    end
end
类注册控制器{:error=>“团队代码无效”}
结束
结束
受保护的
注册后的def路径(资源)
UserSession.create(用户标识:当前用户标识,登录时间:DateTime.now,上次操作时间:DateTime.now,num团队成员:参数[:用户][:num团队成员])
根路径
结束
结束
用户\u模型

Processing by RegistrationsController#create as HTML
 Parameters: {"utf8"=>"✓", "authenticity_token"=>"0JW4oOs+D9plubsIxDxO2N8RjiQtCpuSNE92hJqCQ/N6QkYTFPqnSxmSeqhiKBFFySCzRgG3L+TbQJKZCF9zmQ==", "user"=>{"username"=>"jantesting1", "email"=>"jantesting1@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "team_code"=>"cat45", "num_team_members"=>"0", "accept_terms"=>"1"}, "commit"=>"Sign up"}
##### current_user does not exist #####
 Team Exists (0.4ms)  SELECT  1 AS one FROM `teams` WHERE `teams`.`code` = 'cat45' LIMIT 1
 ↳ app/controllers/registrations_controller.rb:4
  (0.2ms)  BEGIN
 ↳ app/controllers/registrations_controller.rb:5
 User Exists (1.5ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY 'jantesting1@gmail.com' LIMIT 1
 ↳ app/controllers/registrations_controller.rb:5
 User Create (0.6ms)  INSERT INTO `users` (`email`, `encrypted_password`, `created_at`, `updated_at`, `username`) VALUES ('jantesting1@gmail.com', '$2a$11$TiHmwBmI/FmcSXk.ypKu2esrr9nKGoEpjiDPaxQanlD7n6ZQx3/T2', '2020-01-29 18:05:22', '2020-01-29 18:05:22', 'jantesting1')
 ↳ app/controllers/registrations_controller.rb:5
  (0.3ms)  COMMIT
class User < ApplicationRecord
  belongs_to :team, optional: true
  has_many :readiness_factor_responses, dependent: :destroy
  has_many :user_sessions, dependent: :destroy
  has_many :activity_plan_users, dependent: :destroy

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :username,
    presence: true,
    length: { minimum: 2 }

  attr_accessor :team_code
  attr_accessor :num_team_members
  attr_accessor :accept_terms


  def is_admin?
    self.admin
  end

  def step_and_substep
    [self.current_step, self.current_substep]
  end

  def current_session
    # weak way to handle the case where other teammates have signed up but not logged in
    if self.user_sessions
      self.user_sessions.order("created_at").last
    else
      nil
    end
  end

  # user is defined as idle if they haven't taken an action in 30 min. They will also be forced to reauth by devise
  def is_idle?
    if self.current_session && self.current_session.last_action_time
      (Time.now - self.current_session.last_action_time) > 1800
    end
  end

end
class用户1800
结束
结束
结束

您是否尝试在生产模式下运行您的本地计算机?有趣的想法-刚刚测试过,即使在生产模式下,仍然可以在本地获得正确的行为…这些db列可能不应该为空。我从您的服务器输出中注意到,用户已经存在,但它看起来也会用这些信息重新创建一个用户。如果用户存在,为什么要重新创建用户?可能不是这个问题的解决方案,但代码中确实出现了一些奇怪的事情。您可以发布注册控制器代码吗?用户模型可能也很有用