It's not too big of a deal here, but I'd usually do the computation of SecureRandom.urlsafe_base64(6) in the controller then pass it into the view as a parameter.