Sha256: 28677808d2cea093a28951a0e7d8d8b4547f2d765d76285f6c85ff3953ab5473

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module NippoCore
  class GroupsController < ApplicationController
    include Pundit

    before_action :initialize_group, only: [:new, :create]
    before_action :find_group, except: [:index, :new]

    def index
      @groups = NippoCore::Group.order(created_at: :desc).page(params[:page]).per(10)
    end

    def new
    end

    def show
      @reports = @group.reports.order(reported_at: :desc).limit(5)
      @requests = @group.unaccepted_requests.limit(5)
      @members = @group.members
    end

    def create
      if @group.save
        current_user.add_member(current_user, @group)
        redirect_to root_path
      else
        render 'new', status: 400
      end
    end

    def edit
      authorize @group
      render layout: nil
    end

    def update
      authorize @group
      if @group.update(group_params)
        redirect_to @group
      else
        head 400
      end
    end

    def request_join
      result = current_user.send_request(@group)
      render layout: nil
    end

  private
    def initialize_group
      @group = NippoCore::Group.new(group_params.merge(creator: current_user))
    end

    def group_params
      params.fetch(:group, {}).permit(:name, :description)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nippo_core-1.0.0 app/controllers/nippo_core/groups_controller.rb