Class: MyAccountsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



54
55
56
57
58
59
60
61
62
# File 'app/controllers/my_accounts_controller.rb', line 54

def destroy
  @profile = current_user.profile
  @profile.destroy

  respond_to do |format|
    format.html { redirect_to , notice: 'devise.registrations.destroyed' }
    format.json { head :no_content }
  end
end

#editObject



13
14
15
16
# File 'app/controllers/my_accounts_controller.rb', line 13

def edit
  @profile = current_user.profile
  prepare_options
end

#showObject



4
5
6
7
8
9
10
11
# File 'app/controllers/my_accounts_controller.rb', line 4

def show
  @profile = current_user.profile

  respond_to do |format|
    format.html
    format.json { render json: @profile }
  end
end

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/my_accounts_controller.rb', line 18

def update
  @profile = current_user.profile
  user_attrs = [
    :id, :email, :current_password, :password, :password_confirmation
  ]
  user_attrs += [
    {:user_has_role_attributes => [:id, :role_id]}
  ] if current_user.has_role?('Administrator')

  user_params = ActionController::Parameters.new(params[:profile][:user_attributes]).permit(*user_attrs)

  respond_to do |format|
    saved = current_user.update_attributes(user_params)
    @profile.assign_attributes(profile_params)

    if saved
      if @profile.save
        (current_user, bypass: true)
        format.html { redirect_to , notice: t('controller.successfully_updated', model: t('activerecord.models.user')) }
        format.json { head :no_content }
      else
        prepare_options
        format.html { render action: "edit" }
        format.json { render json: current_user.errors, status: :unprocessable_entity }
      end
    else
      current_user.errors.full_messages.each do |msg|
        @profile.errors[:base] << msg
      end
      prepare_options
      format.html { render action: "edit" }
      format.json { render json: current_user.errors, status: :unprocessable_entity }
    end
  end
end