1
"please contact your <%[email protected] %>  mentor" 

I am using the above syntax and it is wrong.

Can anyone please tell me the correct syntax for interpolating @user.name into a string using " ".

1
  • if we answered your question can you accept one of the answers please? Commented Jun 3, 2011 at 18:05

3 Answers 3

3
"please contact your #{@user.name }  mentor"

if you just want to call .to_s on @user you can do

"please contact your #@user  mentor"

and omit the {}

<%=...%> is for eRB files, use "#{}" to substitute in quotes

Sign up to request clarification or add additional context in comments.

Comments

3

The <%= %> format is for erb template files. If you want to do string interpolation within standard Ruby code, use the #{ } format instead.

"please contact your #{@user.name} mentor"

3 Comments

This is for double quote..what is the syntax for signle quote??
You can't do it with single quotes, Ruby will only apply interpolation with double quotes.
'please contact your ' + @user.name + ' mentor' - for single quotes :), but this is not interpolation, this is concatenation.
2

That is the correct syntax for an erb template. for ruby it is

"please contact your #{@user.name} mentor"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.