[RUBY] When I deployed it to heroku, "We're sorry, but something went wrong. If you are the application owner check the logs for more information." Stood out.

I am a beginner in programming. Misrecognition, isn't it wrong in the first place? I would be grateful if you could teach me that.

・ Cause of error ・ Method to discover the cause ・ Why the cause is an error

Is described.

After deploying heroku, "We're sorry, but something went wrong. If you are the application owner check the logs for more informatio" stood out on a specific page.

There was an error on the page that transitions after user registration. デプロイエラー.PNG

I was able to display it in the local development environment (cloud9) without any problems ... After the error occurred, I tried googled, tried googled repeatedly, and solved it safely over a day and a half.

__ Well, what was the cause __

Conclusion

The description of the action of the corresponding controller was incorrect.

@user = User.find_by(params[:id])
#mistake

@user = User.find(params[:id])
#This is correct

Learn

The key to this problem is not the answer that the __method was different, but the way to resolve the error. __

The method of fishing is more reproducible than the method of catching fish. This is the first time I have been worried about programming for more than a day since I started learning programming by myself. You have to think about how to deal with the error.

** From this error, I will summarize what to do when a heroku error occurs. ** **

We're sorry, but something went wrong

デプロイエラー.PNG

This error seems to occur due to various causes such as method mistake, syntax_error, migration file is not reflected like this time.

Like me, most of them __ ① DB problem ② Code problem __ It seems that there are many patterns solved by.

Regarding (1), the id number of the URL increases every time you register, so it seems that you can register. In case of ②, you have to find the error in many directories.

My heart broke. I don't know where the cause is.

How to find the cause of heroku error

There are various methods, but

At the terminal

heroku logs --tail 
(heroku logs --t is also acceptable)

Now you have confirmed the details of the error.

However, beginners do not know where the error is written.

Therefore, at first, I took a quick look.

The reason why it took so long this time is that I didn't face this log properly. __

Even if you look at Qiita, teratail, and blogs, it says "check with the log".

It's important, so I'll say it again! !!

__ Error message, face log properly! !! __

If you take a closer look

Completed 500 Internal Server Error in 6ms (ActiveRecord: 1.9ms | Allocations: 568)

Besides, there was another error.

ActiveRecord::StatementInvalid (PG::DatatypeMismatch: ERROR:  argument of WHERE must be type boolean, not type integer)

You wrote an error in ActiveRecord.

The content of the error is __ "The argument of where must be a boolean value, not an integer." __ And that

Is there a mistake in searching from the database? And found a code mistake at the beginning.

Difference between "find" and "find_by"

reference Rails tutorial https://qiita.com/nakayuu07/items/3d5e2f8784b6f18186f2 https://qiita.com/tsuchinoko_run/items/f3926caaec461cfa1ca3

__find method __

First, find can be searched by the primary key (automatically id in rails). params [: id] returns a number as a string (eg '1'), but the find method will automatically convert it to an integer.

for that reason

User.find(params[:id])

#When

User.find(integer)

Equivalent.

__ Then what about find_by? __ Methods that can be searched by other than the primary key As a syntax

User.find_by(id: 1)
User.find_by(name: "em")

In other words, the code at the time of the error did not know which attribute was searched.

User.find_by(1)

Because it was, it naturally becomes an error.

Unresolved: Why User.find_by (1) was working in a local development environment

I try to check whether the routing to the corresponding page, the action, and the display of html.erb are working properly in the integration test, and both find and find_by return in Green.

I don't know the reason so far. I will add it when I understand it.

Learning summary

・ Face error messages and logs firmly · Heroku errors can be seen on heroku logs --t ・ Difference between "find" and "find_by"

Recommended Posts

When I deployed it to heroku, "We're sorry, but something went wrong. If you are the application owner check the logs for more information." Stood out.
[Heroku] At the time of deployment We're sorry, but something went wrong. Solution
When you deploy to Heroku but it doesn't reflect well