Forum: Ruby on Rails creating variables on the fly with a loop

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ben (Guest)
on 2006-05-11 21:29
I'm trying to clean up some of my sloppy code, and one of the things I'm
working on is trying to make this huge group of variables a bit more

My variables look like this:

@business_core_courses =

@written_communication =


It seems like there is a lot of repition going on, and that this could
be cleaned up somehow.

the "business_core_courses" and "written_communication" are both just
values in a field name 'title' in the table 'categories'

I was thinking it would look something along the lines of this:

Categories.title.each do |column|
 @category.title = Category.find_by_title('category.title').courses

But I'm not too sure what the right syntax to use is.

Any help would be greatly appreciated.
This topic is locked and can not be replied to.