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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -