Created
December 5, 2019 05:02
-
-
Save Haguilar91/883a23c479be9da2861bc8f0db18937d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatsController < ApplicationController | |
def new | |
@chat = Chat.new | |
end | |
def index | |
@chat = Chat.new | |
@room = Room.new | |
end | |
def create | |
@chat = Chat.create(msg_params) | |
if !room_found | |
@chat.room_id = Room.maximum(:id)+1 | |
else | |
@chat.room_id = @room_found.id | |
end | |
@room = Room.create | |
if @chat.save | |
ActionCable.server.broadcast "room_channel", | |
content: @chat.message | |
else | |
end | |
end | |
private | |
def msg_params | |
params.require(:chat).permit(:message) | |
end | |
def find_room | |
@room_found=Room.where("user_id = :name AND doctor_id = :doctor_id", user_id: current_user.id doctor_id: params[doctor_id]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RoomsController < ApplicationController | |
before_action :authenticate_user! | |
def create | |
@room = Room.new | |
@room.user_id = current_user.id | |
@room.doctor_id = params[:doctor_id] | |
@room.save | |
end | |
def index | |
@room = Room.new | |
end | |
# def room_params | |
# params.require(:room).permit(:user_id, :doctor_id) | |
#end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment