rails 오류 대상의 기본 메시지 다시 쓰기

1315 단어 errorMessageRails
나는 초보자다.이것은 기념할 만한 첫 번째 보도다.
발리데이 테스트 코드를 썼는데 갑자기 어떻게 하면 원래 잘못된 정보를 바꿀 수 있을까 하는 생각이 들어서 조사를 많이 했는데 그 결과 아래의 작법으로 순조롭게 진행되어서 공유해 봤어요.

첫번째


원시 오류문을 전제로 한 테스트 코드

it "is invalid if not having uniqe email" do
      user = create(:user)
      user2 = build(:user)
      user2.valid?
      expect(user2.errors[:email]).to include("has already been taken")
    end
    it "is invalid without a password" do
      user = build(:user, password: "", password_confirmation: "")
      user.valid?
      expect(user.errors[:password]).to include("can't be blank")
    end

테스트 결과



en.다시 쓰기

en:
  activerecord:
    errors:
      messages:
        blank: "what the fuck!!! You need to fill it"
        taken: "what the hell are you thinking? it already exists"
  hello: "Hello world"

테스트 결과



이것뿐이다

좋은 웹페이지 즐겨찾기