Class: Profiles::EmailsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/profiles/emails_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/profiles/emails_controller.rb', line 7

def create
  @email = current_user.emails.new(email_params)

  if @email.save
    NotificationService.new.new_email(@email)
  else
    flash[:alert] = @email.errors.full_messages.first
  end

  redirect_to profile_emails_url
end

#destroyObject


19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/profiles/emails_controller.rb', line 19

def destroy
  @email = current_user.emails.find(params[:id])
  @email.destroy

  current_user.update_secondary_emails!

  respond_to do |format|
    format.html { redirect_to profile_emails_url }
    format.js { render nothing: true }
  end
end

#indexObject


2
3
4
5
# File 'app/controllers/profiles/emails_controller.rb', line 2

def index
  @primary = current_user.email
  @emails = current_user.emails
end