Skip to content

Instantly share code, notes, and snippets.

@ecnalyr
Created August 24, 2015 14:53
Show Gist options
  • Save ecnalyr/8ff0a7cc8b18e16c3b2a to your computer and use it in GitHub Desktop.
Save ecnalyr/8ff0a7cc8b18e16c3b2a to your computer and use it in GitHub Desktop.
# needs to return either a blank array or an array of place_preferences
def current_place_preferences
if PlacePreference.where(venue_uuid: current_place.id).blank?
[]
else
# restrict list if there is a role involved
if current_user.roles.present?
place_preferences = []
current_user.roles.each do |role|
if role.place_preference.present? && role.place_preference.venue_uuid == current_place.id
place_preferences << role.place_preference
end
end
return place_preferences if place_preferences.present?
end
# fallback if the user has no roles
PlacePreference.where(venue_uuid: current_place.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment