0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails DM機能 メッセージ編

Posted at

class MessagesController < ApplicationController
before_action :authenticate_user!, :only => [:create]

def create #room_idには@room.idを渡される(二人がDM時に開いているルームのID)
if Entry.where(:user_id => current_user.id, :room_id => params[:message][:room_id]).present?  #ログインしているユーザーの、二人がDM時に開いているルームに入った情報があるか[:message]には作ったメッセージに渡されたルームIDとコンテンツが入っている
@message = Message.create(params.require(:message).permit(:user_id, :content, :room_id).merge(:user_id => current_user.id))
redirect_to "/rooms/#{@message.room_id}"
else
redirect_back(fallback_location: root_path)
end
end
end

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?