TypeError no implicit conversion of nil into String

I'm trying to add social sharing to a Rails project, but I keep getting this no implicit conversion of nil into String on both lines below:

<a href="http://www.facebook.com/sharer/sharer.php?u=<%= CGI::escape(root_url) %>?ref=<%= CGI::escape(@user.referral_code) %>&title=wdyw" class="fb" target="_blank"></a>

<a href="http://twitter.com/share?url=<%= CGI::escape(root_url) %>?ref=<%= CGI::escape(@user.referral_code) %>&text=<%= CGI::escape(twitter_message) %>" class="twit" target="_blank"></a>

I'm on ruby version 2.6. Not sure what the error is.