을 방지 저장 :레일의 유효성을 검사 나는이 같은 사용자 모델이
class OrdersController < ApplicationController
.
.
.
def create
@order = Order.new(params[:order])
if @order.save
if @order.purchase
response = GATEWAY.store(credit_card, options)
result = response.params['billingid']
@thisuser = User.find(current_user)
@thisuser.billing_id = result
if @thisuser.save
redirect_to(root_url), :notice => 'billing id saved')
else
redirect_to(root_url), :notice => @thisuser.errors)
end
end
end
end
: 사용자 모델에서
class User < ActiveRecord::Base
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
.
.
.
end
, 나는 나는이처럼 보이는 OrdersController가에서로 저장할 BILLING_ID 열이를
사용자 모델이 validates :password
이므로 @thisuser.save
은 저장되지 않습니다. 그러나 일단 유효성 검증을 주석 처리하면 @thisuser.save
이 true를 리턴합니다. 이 유효성 검사는 새 사용자를 만들 때만 작동한다고 생각했기 때문에 이것은 나에게 익숙하지 않은 영역입니다. 누군가 사용자 모델에 저장하려고 할 때마다 validates :password
이 실행되어야한다고 말 할 수 있습니까? 감사합니다
굉장합니다. 고마워요, Tadman. 정말 고마워. – railslearner