<commit_before>class MessagesController < ApplicationController
  #before_action :require_login
  #before_action :validate_request_status, only: [:create]

  def index
    #@messages = @request.messages
  end

  def create
  end

  private

  def require_login
    unless current_user == @request.requester || current_user == @request.responder
      flash[:error] = "This action requires you to be logged in"
      redirect_to login_path
    end
  end

  def validate_request_status
    unless @request.active?
      flash[:error] = "This request is no longer active."
    end
  end

 def find_request
  @request = Request.find_by(id: params[:request_id]).messages.include(:messages)
 end
end<commit_msg>Add necessary_before actions to the Messages controller.<commit_after>class MessagesController < ApplicationController
  before_action :set_request, :require_login, :verify_association
  before_action :validate_request_status, only: [:create]

  def index
    @messages = @request.messages
  end

  def create
    @message = Message.new(message_params)

    if @message.save
      trigger_message_event(@message)
    else
      flash[:now] = @message.errors.full_messages.join(', ')
      render request_messages_path(@request)
    end
  end

  private

 def set_request
  @request = Request.find_by(id: params[:request_id]).messages.include(:messages)
 end

  def require_login
    unless current_user
      flash[:error] = "You must be loged in to before this action".
      redirect_to login_path
    end
  end

  def verify_association
    unless current_user == @request.requester || current_user == @request.responder
      flash[:error] = "You are not a party to this neighborly request."
      redirect_to root_path
    end
  end

  def validate_request_status
    unless @request.active?
      flash[:error] = "This request is no longer active."
    end
  end

  def message_params
    known_attrs = {author_id: current_user.id, request_id: @request.id}

    params.require(:message).permit(:content).merge(known_attrs)
  end

  def trigger_message_event(message)
    Pusher["private-#{@<EMAIL>}"].trigger('new_message', {content: message.content})
  end
end
{'fraction_non_alphanumeric': 0.08977900552486189, 'fraction_numerical': 0.0, 'mean_word_length': 3.894144144144144, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7573796', 'n_tokens_mistral': 648, 'n_tokens_neox': 632, 'n_words': 168}