Probably this is a ruby trick instead of Rails’. But the context of my
question is in Rails.
There are a lot of prompt to user in our Rails app. I don’t want to
hard-code those prompt every where, since they will be change by the
product team. Then I put all of them in a yml file and load the yml
file as a hash to read the prompts in controllers.
All works fine except that sometimes there needs to be some dynamic
content in the prompts. Like
<%=boy%> kissed <%=girl%>
Then I used ERB to substitute the dynamic content:
boy = “Tom”
girl = “Jenny”
raw_string = load_yml[‘test_prompt’]
That works, but it make each call a bit hurt. I want to be able to
flash[:notice] = properties[‘test_prompt’], or
flash[:notice] = properties ‘test_prompt’
And it is able to substitute those local variables. So I def a method
called properties to load yml and use ERB to analyze the dynamic
content. But the problem is how to get the binding of the caller?
Or is there any other “beautiful” way to make property files dynamic?