Sha256: 82592d1ba0b3a4d1eddd04e2f5a6251dd0b22e0307299746833ad8d9b490c7bf

Contents?: true

Size: 699 Bytes

Versions: 20

Compression:

Stored size: 699 Bytes

Contents

class MessagesController < AjaxController
  before_action :set_exercise!, only: [:create, :read_messages]

  def index
    render json: {has_messages: has_messages?, messages_count: messages_count}
  end

  def read_messages
    @exercise.messages_for(current_user).read_all!
    index
  end

  def create
    @exercise.submit_question! current_user, message_params
    redirect_to @exercise
  end

  def errors
    render 'messages/errors', layout: false
  end

  private

  def set_exercise!
    exercise_id = params.dig(:message, :exercise_id)  || params[:exercise_id]
    @exercise = Exercise.find(exercise_id)
  end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mumuki-laboratory-5.5.0 app/controllers/messages_controller.rb
mumuki-laboratory-5.4.0 app/controllers/messages_controller.rb
mumuki-laboratory-5.3.0 app/controllers/messages_controller.rb
mumuki-laboratory-5.2.1 app/controllers/messages_controller.rb
mumuki-laboratory-5.2.0 app/controllers/messages_controller.rb
mumuki-laboratory-5.1.1 app/controllers/messages_controller.rb
mumuki-laboratory-5.1.0 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.12 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.11 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.10 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.9 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.8 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.7 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.6 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.5 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.4 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.3 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.2 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.1 app/controllers/messages_controller.rb
mumuki-laboratory-5.0.0 app/controllers/messages_controller.rb