fixed SQL being in controllers into active record queries using joins