Skip to content

Commit

Permalink
Only list microcosms with at least 2 members.
Browse files Browse the repository at this point in the history
  • Loading branch information
openbrian committed Jan 28, 2021
1 parent 2edcccc commit 9f460fb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/microcosms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ def index
morning = "(60 * 6)" # 6 AM
long_facing_sun = "(#{minute_of_day} + #{morning}) / 4"
# Using Arel.sql here due to warning about non-attributes arguments will be disallowed in Rails 6.1.
@microcosms = Microcosm.order(Arel.sql("longitude + 180 + #{long_facing_sun} DESC"))
# Only list out microcosms that have at least 2 members in order to mitigate spam. In order to get
# a microcosm listed, the organizer must find 2 members and give them the link to the page manually.
@microcosms = Microcosm
.joins(:microcosm_members)
.group('microcosms.id')
.having("COUNT(microcosms.id) > 2")
.order(Arel.sql("longitude + 180 + #{long_facing_sun} DESC"))
end

# GET /microcosms/mycity
Expand Down

0 comments on commit 9f460fb

Please sign in to comment.