A little background:
My app has two models called
map belongs to a
group and a
user belongs to
group. You can go in a group and add maps which is how maps are "assigned" to a user. These will show up on their dashboard.
class User < ApplicationRecord def fetch_maps @groups = self.groups @maps = Array.new @groups.each do |g| g.maps.each do |m| @maps << m end end return @maps end end
In order to display the maps the user should have shown in their dashboard I created a
fetch_maps method to call on the current user.
Im wondering if there is any way to clean this up or really just any feedback. This is the first method I have written with current Ruby knowledge.
class Mapgroup < ApplicationRecord belongs_to :map, optional: true belongs_to :group, optional: true end
class Usergroup < ApplicationRecord belongs_to :user, optional: true belongs_to :group, optional: true end