summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-10-15 10:11:56 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-10-28 21:32:17 +0100
commit57af2ee2e51b614ac6e2fa81b1075a55d3c0c252 (patch)
tree81731790772b47e444b8a1abb70abdec543da2dd /lib
parentc69ab8c2bc8dfa59070249dd434219d83a792dbc (diff)
downloadnorsk-urskog-registrations-57af2ee2e51b614ac6e2fa81b1075a55d3c0c252.tar.gz
norsk-urskog-registrations-57af2ee2e51b614ac6e2fa81b1075a55d3c0c252.tar.bz2
norsk-urskog-registrations-57af2ee2e51b614ac6e2fa81b1075a55d3c0c252.zip
Retain member and song info on errors in form.
Diffstat (limited to 'lib')
-rw-r--r--lib/member.rb14
-rw-r--r--lib/song.rb14
2 files changed, 17 insertions, 11 deletions
diff --git a/lib/member.rb b/lib/member.rb
index 0fb69b5..598b5f4 100644
--- a/lib/member.rb
+++ b/lib/member.rb
@@ -1,10 +1,16 @@
class Member
attr_reader :name, :instrument, :age
- def initialize(params)
- @name = params['name']
- @instrument = params['instrument']
- @age = params['age'].to_i
+ def initialize(params = nil)
+ if params
+ @name = params['name']
+ @instrument = params['instrument']
+ @age = params['age'].to_i
+ else
+ @name = ''
+ @instrument = ''
+ @age = 0
+ end
end
def to_s
diff --git a/lib/song.rb b/lib/song.rb
index 93172f2..482834e 100644
--- a/lib/song.rb
+++ b/lib/song.rb
@@ -1,13 +1,13 @@
class Song
attr_reader :title, :time, :isrc, :composers, :performers, :notes
- def initialize(params)
- @title = params['title']
- @time = params['time']
- @isrc = params['isrc']
- @composers = params['composers'].split("\n")
- @performers = params['performers'].split("\n")
- @notes = params['notes']
+ def initialize(params = nil)
+ @title = params ? params['title'] : ''
+ @time = params ? params['time'] : ''
+ @isrc = params ? params['isrc'] : ''
+ @composers = params ? params['composers'].split("\n") : []
+ @performers = params ? params['performers'].split("\n") : []
+ @notes = params ? params['notes'] : ''
end
def to_s