Class: HouseholdsController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/households_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/households_controller.rb', line 34

def create
  @household = current_organization.households.create(params[:household])

  # NOTE: No mind is paid to any household these people might already be in
  params[:individuals].reject(&:empty?).each do |i|
    @household.individuals << current_organization.individuals.find(i)
  end

  if @household.save
    redirect_to @household
  else
    render :new
  end
end

#ignore_suggestedObject



65
66
67
68
69
# File 'app/controllers/households_controller.rb', line 65

def ignore_suggested
  suggested = SuggestedHousehold.find(params[:suggested_id])
  suggested.update_attributes(:ignored => true)
  redirect_to suggested_households_path
end

#indexObject



54
55
56
57
# File 'app/controllers/households_controller.rb', line 54

def index
  @households = current_organization.households.order(:created_at)
  @households = @households.paginate(:page => params[:page], :per_page => 20)
end

#newObject



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

def new
  @household = Household.new
  if params[:individuals]
    params[:individuals].each do |i|
      @household.individuals << current_organization.individuals.find(i)
    end
  end
end

#showObject



49
50
51
52
# File 'app/controllers/households_controller.rb', line 49

def show
  @household = current_organization.households.find(params[:id])
  @actions = @household.actions.includes(:person, :organization).paginate(:page => params[:page], :per_page => 20)
end

#suggestedObject



59
60
61
62
63
# File 'app/controllers/households_controller.rb', line 59

def suggested
  hs = HouseholdSuggester.new(current_organization)
  @by_address = hs.by_address
  @by_spouse = hs.by_spouse
end

#updateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/households_controller.rb', line 14

def update
  @household = current_organization.households.find(params[:id])
  flash[:notice] = []

  unless params[:individual_ids].nil?
    @household.individuals << current_organization.individuals.find(params[:individual_ids])
  end

  @household.update_attributes(params[:household])
  @household.update_member_addresses if @household.overwrite_member_addresses

  if @household.save
    flash[:notice] = "Your changes have been saved"
  else
    flash[:alert] = @household.errors.full_messages.to_sentence
  end

  redirect_to(@household)
end