Creating variables on the fly with a loop

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs