Essentially I'm trying to perform this comparison
request.fullpath == "/contacts/"+current_user.id
What is the best way to concatenate a string with a variable to perform a comparison like this?
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
The most efficient is to use StringBuilder, like so: StringBuilder sb = new StringBuilder(); sb. Append("string1"); sb.
Instead of terminating the string and using the + operator, you enclose the variable with the #{} syntax. This syntax tells Ruby to evaluate the expression and inject it into the string.
You can interpolate it as request.fullpath == "/contacts/#{current_user.id}"
"/contacts/#{current_user.id}"
Always use String interpolation, it's faster than <<
and +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With