You are doing a query in view, better to do this in the controller and pass an instance variable