3

How I can store ruby string with variables in DB? For example I have model Stack and attribute welcome_message. I want store in welcome_message next string - "Hi, #{user}. How do you do?" Then I make:

user = "artem"
p stack.welcome_message

and got-

"Hi, \#{user}. How do you do?"

I can't fixate it in view, because I want change position varibles in field.

1 Answer 1

3

store you welcome message like this

Hi, <user>. How do you do?

and then, while displaying,

user = "artem"
p stack.welcome_message.gsub('<user>', user)

Its like adding a placeholder for user name.

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

1 Comment

Why not %{user} and String#%?

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.