Clive,

It seems to me that you could just pass binding to the properties
method you define. For example:

require 'erb'

def properties(text_key, b)
  return ERB.new("<%= boy %> kissed <%= girl %>").result(b)
end

boy = "Tom"
girl = "Jenny"
puts properties("something", binding)


The above outputs the expected "Tom kissed Jenny" since at the time
properties is called the method binding points to the context
containing both boy and girl.  Does this answer your question?

On Mar 2, 2:31 pm, Clive <lin....@gmail.com> wrote:
> 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']
> flash[:notice]=ERB.new(raw_string).result(binding)
>
> That works, but it make each call a bit hurt. I want to be able to
> just:
> 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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to