Files
grecia/app/controllers/communities_controller.rb
Javi Martín d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +02:00

41 lines
981 B
Ruby

class CommunitiesController < ApplicationController
TOPIC_ORDERS = %w[newest most_commented oldest].freeze
before_action :set_order, :set_community, :load_topics, :load_participants
has_orders TOPIC_ORDERS
skip_authorization_check
def show
raise ActionController::RoutingError, "Not Found" unless communitable_exists?
redirect_to root_path if Setting["feature.community"].blank?
end
private
def set_order
@order = valid_order? ? params[:order] : "newest"
end
def set_community
@community = Community.find(params[:id])
end
def load_topics
@topics = @community.topics.send("sort_by_#{@order}").page(params[:page])
end
def load_participants
@participants = @community.participants
end
def valid_order?
params[:order].present? && TOPIC_ORDERS.include?(params[:order])
end
def communitable_exists?
@community.proposal.present? || @community.investment.present?
end
end