conversations_controller.rb 594 B

123456789101112131415161718192021222324
  1. class ConversationsController < ApplicationController
  2. before_action :set_conversation, only: [:show]
  3. before_action :check_permission, only: [:show]
  4. def show
  5. end
  6. private
  7. def set_conversation
  8. @conversation = Conversation.find(params[:id])
  9. end
  10. def check_permission
  11. unless current_user.conversations.include? @conversation
  12. flash[:danger] = "You are not part of this conversation"
  13. redirect_to root_path
  14. end
  15. end
  16. def conversation_params
  17. params.require(:conversation).permit(:name, messages_attributes: [:content])
  18. end
  19. end