Sha256: fa4201f0d28eee0856451ebc80c1149938f2ab4efebda37e0da30b8d1e245251

Contents?: true

Size: 802 Bytes

Versions: 66

Compression:

Stored size: 802 Bytes

Contents

class DiscussionsMessagesController < AjaxController
  before_action :set_discussion!, only: [:create, :destroy]
  before_action :authorize_user!, only: [:destroy, :approve]

  def create
    @discussion.submit_message! message_params, current_user
    redirect_back(fallback_location: root_path)
  end

  def destroy
    current_message.destroy!
    redirect_back(fallback_location: root_path)
  end

  def approve
    current_message.toggle_approved!
    head :ok
  end

  private

  def set_discussion!
    @discussion ||= Discussion.find_by(id: params[:discussion_id])
  end

  def authorize_user!
    current_message.authorize! current_user
  end

  def current_message
    @message ||= Message.find(params[:id])
  end

  def message_params
    params.require(:message).permit(:content)
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
mumuki-laboratory-7.6.2 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.6.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.6.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.5.2 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.5.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.5.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.4.2 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.4.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.4.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.3.1 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.3.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.2.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.1.0 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.12 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.11 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.10 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.9 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.8 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.7 app/controllers/discussions_messages_controller.rb
mumuki-laboratory-7.0.6 app/controllers/discussions_messages_controller.rb