Hi all,
Currently I’m having to do this:
def self.authorized_roles(controller, action)
specific = self.find_by_controller_and_action(controller, action)
all_actions = self.find_by_controller_and_action(controller, ‘’)
all_controllers = self.find_by_controller(’’)
role_ids = []
specific.each do |role_item|
role_ids << role_item.role_id
end
all_actions.each do |role_item|
role_ids << role_item.role_id
end
all_controllers.each do |role_item|
role_ids << role_item.role_id
end
role_ids.flatten.uniq
end
which of course is not DRY at all.
I could not find how to merge class instances (specific, all_actions
and all_controllers) or how to make only one find to use the selection
statements above (at least not in a easy to read way)
It would be better if I could do something like:
def self.authorized_roles(controller, action)
specific = self.find_by_controller_and_action(controller, action)
all_actions = self.find_by_controller_and_action(controller, ‘’)
all_controllers = self.find_by_controller(’’)
#
# MAGIC
#
role_ids = []
role_items do |role_item|
role_ids << role_item.role_id
end
role_ids.flatten.uniq
end
Thanks!