-2
私はユーザーモデルを持っており、ユーザーはサインフォームで国のドロップダウンと国籍IDを持っています。ユーザーがxx国を選択すると、国籍IDの4番目と5番目の桁は "78"でなければなりません。また、xx国IDは21です。認証にdeviseを使用しますが、この検証が必要です。親切に私がこの問題を理解するのを手伝ってください。あなたはフィールドが属するコントローラのアクションで検証を置きたいと思うでしょう私はレール検証の問題に直面しています
コントローラ
def create
build_resource(sign_up_params)
if params[:user][:country_id] == 21
if params[:user][:nationality_id][4..5] != "78"
flash[:error] = "The nationality_id is invalid!"
end
end
if resource.save
sign_out resource
reset_session
flash[:heading] = "Thank you for registering with us!"
flash[:message] = "Please confirm your email address through the email sent to your account."
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
私はコントローラのコードを追加しました。見てください – User101
nationality_idはすべてのユーザに一意ですか? 78を国籍に追加する方法はありますか? –