Class: SummerResidents::FamiliesController

Inherits:
SummerResidentsController show all
Defined in:
app/controllers/summer_residents/families_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_user_infoObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/summer_residents/families_controller.rb', line 37

def 
  father = Resident.new
  father.user = @current_user
  @family = Family.new
  @family.father = father

  respond_to do |format|
    format.html  { render action: :new }
    format.json { render json: @family }
  end
end

#createObject

POST /families POST /families.json



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/summer_residents/families_controller.rb', line 51

def create
  @family = Family.new
  [:father, :mother].each do |p|
    pp = params[p].keep_if { |k,v| !v.blank? }

    @family.__send__ "#{p}=", (pp.blank? ? nil : get_user_from_params(pp))
  end

  respond_to do |format|
    if @family.save
      uninitialized_pw = User.initialize_without_password("").password_digest
      [@family.father, @family.mother].select { |p| p }.each { |p|
        user_is_new = p.user.password_digest == uninitialized_pw
        EasyRailsAuthentication::AuthenticationHelper.SendPasswordInitializationEmailTo p.email if user_is_new
      }
      format.html { redirect_to (added_user_info? ? family_url(@family.id) : families_url), notice: 'Family was successfully created.' }
      format.json { render json: @family, status: :created, location: @family }
    else
      format.html { render action: "new" }
      format.json { render json: @family.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /families/1 DELETE /families/1.json



77
78
79
80
81
82
83
# File 'app/controllers/summer_residents/families_controller.rb', line 77

def destroy
  Family.find(params[:id]).destroy
  
  respond_to do |format|
    format.js { render nothing: true }
  end
end

#indexObject

GET /families GET /families.json



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

def index
  @index_action = true
  @families = Family.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @families }
  end
end

#newObject



33
34
35
# File 'app/controllers/summer_residents/families_controller.rb', line 33

def new
  @family = Family.new
end

#showObject

GET /families/1 GET /families/1.json



24
25
26
27
28
29
30
31
# File 'app/controllers/summer_residents/families_controller.rb', line 24

def show
  @family = Family.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @family }
  end
end