Sha256: 4f308b4b1055537c7842a7e16ec86efc4b0e7456f47eea0b0eb66602de07aebf

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true
module Thredded
  class MessageboardsController < Thredded::ApplicationController
    before_action :thredded_require_login!, only: [:new, :create, :edit, :update]

    after_action :verify_authorized, except: %i(index)
    after_action :verify_policy_scoped, except: %i(new create edit update)

    def index
      @groups = MessageboardGroupView.grouped(policy_scope(Messageboard.all))
    end

    def new
      @messageboard = Messageboard.new
      @messageboard_group = MessageboardGroup.all
      authorize_creating @messageboard
    end

    def create
      @messageboard = Messageboard.new(messageboard_params)
      authorize_creating @messageboard
      if Thredded::CreateMessageboard.new(@messageboard, thredded_current_user).run
        redirect_to root_path
      else
        render :new
      end
    end

    def edit
      @messageboard = Messageboard.friendly_find!(params[:id])
      authorize @messageboard, :update?
    end

    def update
      @messageboard = Messageboard.friendly_find!(params[:id])
      authorize @messageboard, :update?
      if @messageboard.update(messageboard_params)
        redirect_to messageboard_topics_path(@messageboard), notice: I18n.t('thredded.messageboard.updated_notice')
      else
        render :edit
      end
    end

    private

    def messageboard_params
      params
        .require(:messageboard)
        .permit(:name, :description, :messageboard_group_id)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thredded-0.12.1 app/controllers/thredded/messageboards_controller.rb
thredded-0.12.0 app/controllers/thredded/messageboards_controller.rb
thredded-0.11.1 app/controllers/thredded/messageboards_controller.rb
thredded-0.11.0 app/controllers/thredded/messageboards_controller.rb
thredded-0.10.1 app/controllers/thredded/messageboards_controller.rb
thredded-0.10.0 app/controllers/thredded/messageboards_controller.rb
thredded-0.9.4 app/controllers/thredded/messageboards_controller.rb
thredded-0.9.3 app/controllers/thredded/messageboards_controller.rb
thredded-0.9.2 app/controllers/thredded/messageboards_controller.rb
thredded-0.9.1 app/controllers/thredded/messageboards_controller.rb