Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user.valid?를 호출했을 경우 phone_number값이 바뀌지 않도록 하기 #332

Open
shaynekang opened this issue Oct 18, 2014 · 2 comments

Comments

@shaynekang
Copy link

사용자(User) 모델의 휴대폰 번호(phone_number) 컬럼에 "010-1234-5678"을 넣고 valid?를 호출하면 휴대폰 번호가 "01012345678"로 Normalize 되네요.

irb(main):113:0> user = User.new
=> #<User id: nil, email: nil, created_at: nil, updated_at: nil, username: nil, phone_number: nil, major: nil, student_id: nil, sex: nil, home_phone_number: nil, emergency_phone_number: nil, habitat_id: nil, member_type: nil, generation_id: nil, birth: nil>
irb(main):114:0> user.phone_number = "010-1234-5678"
=> "010-1234-5678"
irb(main):115:0> user.valid?
  User Exists (0.3ms)  SELECT  1 AS one FROM "users"  WHERE "users"."phone_number" = '01012345678' LIMIT 1
  User Exists (0.2ms)  SELECT  1 AS one FROM "users"  WHERE "users"."email" IS NULL LIMIT 1
=> false
irb(main):116:0> user
=> #<User id: nil, email: nil, created_at: nil, updated_at: nil, username: nil, phone_number: "01012345678", major: nil, student_id: nil, sex: nil, home_phone_number: nil, emergency_phone_number: nil, habitat_id: nil, member_type: nil, generation_id: nil, birth: nil>

사실 좀 미묘한 이슈라 고민을 했는데, 그래도 valid?는 데이터 검증만 하는 메소드인데 값이 바뀌는 건 올바르지 않은 것 같습니다. 수정이 된다면 좋겠네요. ㅎㅎ

@shaynekang
Copy link
Author

아니면 차라리 phone_number를 넣을 때부터 자동으로 normalize 되는 것도 좋을 것 같습니다. ㅎㅎ

@minhyeok4dev
Copy link

저도 유사한 이슈를 겪었습니다.

  • before_save로 normalize하고
  • decorator로 front에 뿌리는 방식
    으로 가면 어떨지 한번 제안해봅니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants