[RUBY] You can solve the problem by referring to the two articles !!!

Hi, this is Teppei Mimachi! !!

When you're proming, you'll find things you don't understand! ?? I think that I will do this for the first implementation and error resolution, but in such a case, I will look it up in a book or ask people, but after all the best thing is to look it up by google Isn't that a thing ...?

At least I have googled to solve more than 90% of the problems.

But ... but.

For example, even if you investigate this and that for the problem that appeared in Ruby on Rails, you can develop the application under exactly the same conditions as the development environment is different, the database is different, the version is different, and the application name is different. The possibility of being there is infinitely 0. There is always a difference somewhere.

If you just copy and paste due to such a subtle difference, you will not be able to implement it or solve the error, and eventually you will be disgusted and stop.

To prevent this from happening, I found one way to solve the problem by paying attention to it when confronting the problem, so I would like to introduce it.

You can solve the problem by referring to the two articles !!!

As the title says, the answer is __ "To solve the problem, you can solve it by referring to the two articles !!!" __. This is the conclusion of this time, but it is difficult to understand by this alone, so please give a reference example!

1. I don't know how to do it ...

First of all, the wall I'm facing when I google it is the place where I don't know how to do it.

As a result of investigating the question, I was in a state of incomprehensible, but this time I was looking for a solution to the problem that I do not know how to write ja.yml.

スクリーンショット 2020-10-20 11.52.42.png

As for the state, I want to display all error messages displayed when the text field "__Introduction" is blank in the post form in Japanese. __

In other words, please enter __Content. You want to make Content in Japanese.

By the way, __Contet is the column name __ of the database (post table) you want to save.

2. Articles that Gugu arrived at

If you google, many similar articles may get caught in the search. While referring to articles that are easy for me to understand and the situation is similar, I Japanese localization of Rails validation error message --Qiita I referred to this article.

As a result of reference ↑ I created __ja.yml__ like this and entered it.

This is Japanese localization of Rails validation error message --Qiita I just copied and pasted the code for Japaneseization of __column names.

This result is actually the image of the post form I showed you earlier. ↓ Reposted. スクリーンショット 2020-10-20 11.52.42.png

Well ... In other words, just copying and pasting the __ code did not solve the problem of wanting to translate this column into Japanese.

3. I don't know how to write ja.yml, so I'll try google again

Something is wrong with ja.yml ... what's wrong ...! ?? In such a question, while re-examining the Japanese localization of error messages, [Change the format of error messages displayed in ActiveRecord validates --Qiita] (https://qiita.com/okeicalm/items/9638250ddfb361d80a16) Discover this article! !!

And with ja.yml,

config/local/models/ja.yml


ja:
  activerecord:
    models:
      user:user
    attributes:
      user:
        name:name

↑ I found the above code!

config/local/models/ja.yml


ja:
  activerecord:
    models:
      event:Event
    attributes:
      event:
        name:event name
        place:Venue
        content:Event content

↑ This is the code I am currently using.

Now let's get back to the title. __ You can solve the problem by referring to the two articles !!! __ Return to.

Looking at the two codes, this is

config/local/models/ja.yml


ja:
  activerecord:
    models:
      user:user
    attributes:
      user:
        name:name

↑ In this code, __user: __,

config/local/models/ja.yml


ja:
  activerecord:
    models:
      event:Event
    attributes:
      event:
        name:event name
        place:Venue
        content:Event content

↑ In this code, I noticed that the __event: __ part is table name ...

[Before] [After] Change it like this ...

The result of restarting the server is スクリーンショット 2020-10-20 11.56.58.png

__ I was able to translate all the error messages into Japanese! !! __

result

Again, __ "To solve the problem, you can solve it by referring to the two articles !!!" __ is now complete.

...For your information.

Recommended Posts

You can solve the problem by referring to the two articles !!!
How to solve the problem that you can not pull image from docker hub with Minikube
[Java] Try to solve the Fizz Buzz problem
Let's solve the FizzBuzz problem!
I tried to solve the problem of "multi-stage selection" with Ruby
[Java] Try to solve the Fizz Buzz problem using recursive processing
The first thing to do before you can use Rails6 Ajax
I tried to solve the paiza campaign problem "Challenge from Kaito 813"
I tried to solve the problem of Google Tech Dev Guide
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
What to do if you don't like the code generated by swagger-codegen-cli
How to embed and display youtube videos in Rails (You can also get the URL you entered by editing)
Use the where method to narrow down by referring to the value of another model.
What to do if you can't activate the select box created by bootstrap-select
I tried to solve the tribonatch sequence problem in Ruby (time limit 10 minutes)
How to solve the font specification problem dedicated to using IntelliJ IDEA (Win x64)
Try to save the data that can be read by JavaFX as PNG