Class: AddressesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/addresses_controller.rb', line 12

def create
  @address = current_user.addresses.new(params[:address])
  if @address.save
    flash[:notice] = I18n.t('address_create_ok').capitalize
    return render :partial => 'list', :locals => { :addresses => current_user.addresses }
  else
    flash[:error] = @address.errors
  end
end

#destroyObject



41
42
43
44
45
46
47
48
49
# File 'app/controllers/addresses_controller.rb', line 41

def destroy
  @address = current_user.addresses.find_by_id(params[:id])
  if @address.destroy
    flash[:notice] = I18n.t('address_update_ok').capitalize
  else
    flash[:error] = @address.errors
  end
  render :partial => 'list', :locals => { :addresses => current_user.addresses }
end

#editObject



26
27
28
# File 'app/controllers/addresses_controller.rb', line 26

def edit
  @address = current_user.addresses.find_by_id(params[:id])
end

#indexObject



3
4
5
# File 'app/controllers/addresses_controller.rb', line 3

def index
  render :partial => 'list', :locals => { :addresses => current_user.addresses }
end

#newObject



7
8
9
10
# File 'app/controllers/addresses_controller.rb', line 7

def new
  @address = current_user.addresses.new(params[:address])
  render :action => 'create'
end

#showObject



22
23
24
# File 'app/controllers/addresses_controller.rb', line 22

def show
  @address = current_user.addresses.find_by_id(params[:id])
end

#updateObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/addresses_controller.rb', line 30

def update
  @address = current_user.addresses.find_by_id(params[:id])
  if @address.update_attributes(params[:address])
    flash[:notice] = I18n.t('address_update_ok').capitalize
    return render :partial => 'list', :locals => { :addresses => current_user.addresses }
  else
    flash[:error] = @address.errors
  end
  render :action => 'edit'
end