KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to convert a string value into a name of an attribute that belongs to an object. For example, in the following code, I need all the string values in the column_array turned into attribute names. The names "student_identification" , "email" , etc. are actual column names of my Student table. In the real scenario, column_array will be set by the user (by ticking check boxes). And new_array will be replaced by csv , as I want the data go into a csv file. At the moment I am really struggling at the following line: new_array << r."#{column_array[i]}" I want "#{column_array[i]}" to be turned into the attribute name so I can access the data. def exp_tst @records = Student.find(:all, :conditions=> session[:selection_scope], :order => sort_order('laboratory_id')) column_array = ["student_identification", "laboratory_id", "email", "current_status"] new_array = Array.new() @records.each do |r| (0..(column_array.size-1)).each do |i| new_array << r."#{column_array[i]}" end end end
Tags (comma-separated)
Save Edits
Cancel