polyglot/app/controllers/connections_controller.rb

26 lines
713 B
Ruby
Raw Normal View History

2018-08-31 14:06:42 +00:00
class ConnectionsController < ApplicationController
def new
end
def create
@connection = Connection.new
@connection.user = current_user
contact_user = User.find_by(email: params[:user][:email])
@connection.contact = contact_user
if @connection.save
contact_message = nil
if contact_user.first_name.nil? || contact_user.last_name.nil?
contact_message = "#{contact_user.email}"
else
contact_message = "#{contact_user.first_name} #{contact_user.last_name}"
end
flash[:notice] = "Added #{contact_message} to contacts"
redirect_to contacts_path
2018-08-31 14:06:42 +00:00
else
flash[:alert] = "Invalid email address!"
render 'new'
2018-08-31 14:06:42 +00:00
end
end
end