improve rails query && add update