Class: InvoiceBar::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/invoice_bar/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users POST /users.json



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/invoice_bar/users_controller.rb', line 36

def create
  @user = InvoiceBar::User.new(user_params)
  @user.build_address unless @user.address

  # First user is an administrator
  @user.administrator = true unless InvoiceBar::User.all.size > 0

  respond_to do |format|
    if @user.save
      format.html { redirect_to , notice: t('messages.signed_up') }
      format.json { render json: @user, status: :created, location: @user }
    else
      format.html { render action: "new" }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /users/1 DELETE /users/1.json



76
77
78
79
# File 'app/controllers/invoice_bar/users_controller.rb', line 76

def destroy
  @user.destroy
  respond_on_destroy @user, user_url
end

#editObject

GET /users/1/edit



30
31
32
# File 'app/controllers/invoice_bar/users_controller.rb', line 30

def edit
  respond_on_edit @user
end

#indexObject

GET /users GET /users.json



10
11
12
13
# File 'app/controllers/invoice_bar/users_controller.rb', line 10

def index
  @users = InvoiceBar::User.all.page(params[:page])
  respond_on_index @users
end

#newObject

This is sign up process. GET /users/new



23
24
25
26
27
# File 'app/controllers/invoice_bar/users_controller.rb', line 23

def new
  @user = InvoiceBar::User.new
  @user.build_address
  respond_on_new @user
end

#showObject

GET /users/1 GET /users/1.json



17
18
19
# File 'app/controllers/invoice_bar/users_controller.rb', line 17

def show
  respond_on_show @user
end

#updateObject

Update current user TODO: Allow editing and updating user for administrators



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/invoice_bar/users_controller.rb', line 56

def update
  params[:controller] = 'settings'

  @user = current_user
  @user.update_attributes(user_params)
  @user.address.update_attributes(user_params[:address_attributes])

  respond_to do |format|
    if @user.save
      format.html { redirect_to profile_path, notice: t('flash.actions.update.notice') }
      format.json { render json: @user, status: 200, location: @user }
    else
      format.html { render template: 'invoice_bar/settings/index' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end