There are some great books and courses available on the Refactoring
Cezar Halmagean
Bulletproof Ruby on Rails Applications
Benito Serna
N+1 Queries Basics
Avoid n+1 queries on Rails