Skip to content

Commit

Permalink
checkpoint Bloc#7
Browse files Browse the repository at this point in the history
  • Loading branch information
shaina33 committed Dec 15, 2017
1 parent 59f8d28 commit c9d1c83
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ PATH
remote: ../bloc_record
specs:
bloc_record (1.0.0)
activesupport
sqlite3 (~> 1.3)

GEM
remote: https://rubygems.org/
specs:
activesupport (4.2.5)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
i18n (0.7.0)
json (1.8.3)
minitest (5.9.0)
sqlite3 (1.3.13)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby
Expand Down
1 change: 1 addition & 0 deletions controllers/menu_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def select_address_book_menu
def view_all_entries
@address_book.entries.each do |entry|
system "clear"
puts "Entry from #{entry.address_book.name}"
puts entry.to_s
entry_submenu(entry)
end
Expand Down
7 changes: 2 additions & 5 deletions models/address_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#require 'bloc_record/base'

class AddressBook < BlocRecord::Base

has_many :entries

def add_entry(name, phone_number, email)
Entry.create(name: name, phone_number: phone_number, email: email, address_book_id: self.id)
end
Expand All @@ -18,10 +19,6 @@ def import_from_csv(file_name)
end
end

def entries
Entry.where(address_book_id: self.id)
end

def find_entry(name)
# given in checkpoint #4
Entry.where(name: name, address_book_id: self.id).first
Expand Down
2 changes: 2 additions & 0 deletions models/entry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'bloc_record/base'

class Entry < BlocRecord::Base
belongs_to :address_book

def to_s
"Name: #{name}\nPhone Number: #{phone_number}\nEmail: #{email}"
end
Expand Down

0 comments on commit c9d1c83

Please sign in to comment.