Hi, I have an issue with a variable creating an array... First, I initialize the array. @data = [] Code (markup): Then I add the data. @data << [...] Code (markup): Then I display the results <% @data.each do |data| %> Code (markup): It works great... but if I change the variable name to @x it fails and display an empty array... I dont understand why. Any help please?
There is something weird here... kind of cache or something... I change all variables to @x but in html I leave @data.each do |data| and it keeps sending me the same results...
robzdc, this is not an error thats how variables are meant to function in Ruby. @variable stands for instance variable, by using that variable the data can be used in any function with in the class. When you did @data, u created such a variable and this variable can be accessed in the view. When you use "variable" a local variable is made it has validity only within that function you can't use that variable in the view.
The error was because I'm using the function in lib/ directory, so I have to restart the server to reload the data.
Ah I c, well the reason why you had to restart, to make use of those values was because Rails would load (Loading to memory) the contents of lib/ only during its initial start. Thanks for posting the question, learned something new today..