My question is when do you multiply by y' or when trying to get the derivative?

I know that in this problem that you can do it

In more complicated equations I don't know when to use it. For example in this problem

I don't know where y' belongs. Can anyone help me find out when I have to multiply by y'. I know you are supposed to when you're using the chain rule but I don't know how to do it in that type of problem.

-FP!