How to create a variable name from the value of a string in Ruby on Rails? -
i want create instance variable in controller used in view:
foo = "bar" instance_variable_set("#{foo}", "cornholio")
in view, use @bar that:
@bar => "cornholio"
this generates error: 'bar' not allowed instance variable name
working in rails 3.1
this instance_variable_set("#{foo}", "cornholio")
needs read instance_variable_set("@#{foo}", "cornholio")
based on this post. tried in irb ruby 1.93; post 2009.
Comments
Post a Comment