Class: API::V1::ProfilesController

Inherits:
APIController
  • Object
show all
Defined in:
app/controllers/faalis/api/v1/profiles_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) show



6
7
8
9
# File 'app/controllers/faalis/api/v1/profiles_controller.rb', line 6

def show
  @user = current_user
  respond_with(@user)
end

- (Object) update



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/faalis/api/v1/profiles_controller.rb', line 11

def update
  @user = current_user
  user_fields = {
    :first_name => params[:first_name],
    :last_name => params[:last_name],
    :email => params[:email],
  }

  if params.include? :password and params[:password]
    user_fields[:password] =  params[:password]
    user_fields[:password_confirmation] =  params[:password_confirmation]

    if @user.update(user_fields)
      respond_with(@user)
    else
      respond_to do |format|
        format.json { render :json => {:fields => @user.errors}, :status => :unprocessable_entity }
      end
    end
  else

    if @user.update_without_password(user_fields)
      respond_with(@user)
    else
      respond_to do |format|
        format.json { render :json => {:fields => @user.errors}, :status => :unprocessable_entity }
      end
    end
  end
end