wrote logic in application controller