I have a to-do list with 5 tasks that are stored on the same record.
Todo.task_one, Todo.task_two, etc.
What I would like to do is be able to loop through the fields like this
total_tasks = ["one", "two", "three", "four", "five"]
for tasks in total_tasks
Todo.task_#{tasks} = "text here"
end
However, this doesn't work unless I use eval "Todo.task_#{tasks} = 'text here'"
which I know isn't safe. Even using eval
isn't really the solution, because I need to do this in the view using erb
, so I'm kind of stuck.