我有一个接受银行账户信息和用户信息的支付 api。我捕获了 api 响应并使用 ajax 将信息发送到我的控制器,在那里我尝试将信息保存给我的用户。当我保存时,我收到错误Validation failed: Password can't be blank, Password is invalid:
任何想法?
银行控制器:
def addbank
@user = current_user
@user.phone_number = params[:phone_number]
@user.birth_year = params[:year]
@user.bank_uri = (params['bank_acct_uri'])
@user.save! # <------- ERROR here!
# Code was removed to be more clear
end
用户控制器:
def update
# update user controller has been commented out but the error is still there
end
用户模型:
class User < ActiveRecord::Base
attr_accessible :email,:password,:password_confirmation,:phone_number,:birth_year
attr_accessor :password
before_save :encrypt_password
before_save { |user| user.email = email.downcase }
VALID_PASSWORD_REGEX = # some reg-expression
VALID_PHONE = # some reg-expression
validates_confirmation_of :password
validates :password, presence: true, format:{ with: VALID_PASSWORD_REGEX }
validates :phone_number, format: { with: VALID_PHONE }, if: :phone_number
end