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

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

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