我在rails(4.2.6)中使用devise(4.2.0).
在我的应用程序中,我在用户和配置文件表中使用嵌套属性.我只有在创建新记录时才需要验证密码,在更新创建的记录时未验证密码字段.
我的user.rb文件是:
class User < ActiveRecord::Base
has_one :profile
has_one :company_profile
accepts_nested_attributes_for :profile
attr_accessor :profile_updation
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates_presence_of :email, if: :email_required?
validates_presence_of :password, if: :password_required?
validates_confirmation_of :password, if: :password_required?
protected
def email_required?
true && profile_updation.blank?
end
def password_required?
!password.nil? || !password_confirmation.nil?
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时出现此错误:
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email" DETAIL: Key (email)=() already exists. : INSERT INTO "users" ("first_name", "last_name", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) …Run Code Online (Sandbox Code Playgroud) 我是 reactjs 的新手,安装了 node.js 和 babel。我不清楚为什么我们在 react 中使用 node.js 和 babel。任何人都知道在 react 中推动我。