11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/conversations/conversations_controller.rb', line 11
def create
@user = User.find(params[:user_id])
@conversation = Conversation.new params[:conversations_conversation]
@conversation.user_conversations.build
@conversation.user_conversations.first.user = @user
@conversation.messages = []
@conversation.messages.build body: params[:conversations_conversation][:messages_attributes]['0'][:body], user_id: @user.id
if @conversation.save
redirect_to user_conversation_path(@user, @user.user_conversations.last), notice: 'Conversation was successfully created.'
else
render action: "new"
end
end
|