Class: MyAccountsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



52
53
54
55
56
57
58
59
# File 'app/controllers/my_accounts_controller.rb', line 52

def destroy
  @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
# File 'app/controllers/my_accounts_controller.rb', line 13

def edit
  prepare_options
end

#showObject



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

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

#updateObject



17
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
# File 'app/controllers/my_accounts_controller.rb', line 17

def update
  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)
        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