diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2015-10-05 20:13:33 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2015-10-05 20:13:33 +0200 |
commit | 01987cc0b88fdb0748d8d71cca4f5e40ea8a2604 (patch) | |
tree | 4e24583b5a111f718a342df59fba62ccf439f4f2 /lib | |
parent | 696be9ff4d6a6f7e3286cba14df4e4f449d31bb6 (diff) | |
download | norsk-urskog-registrations-01987cc0b88fdb0748d8d71cca4f5e40ea8a2604.tar.gz norsk-urskog-registrations-01987cc0b88fdb0748d8d71cca4f5e40ea8a2604.tar.bz2 norsk-urskog-registrations-01987cc0b88fdb0748d8d71cca4f5e40ea8a2604.zip |
Redirect back to form and display error if no songs specified.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/band.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/band.rb b/lib/band.rb index 22778ff..49180d8 100644 --- a/lib/band.rb +++ b/lib/band.rb @@ -4,8 +4,10 @@ require_relative 'song' class Band attr_reader :name, :city, :website, :label, :short_bio, :contact, :members, :songs + attr_reader :errors def initialize(params) + @errors = [] @name = params['name'] @city = params['city'] @website = params['website'] @@ -20,8 +22,21 @@ class Band end @songs = [] - params['songs'].each do |k, s| - @songs << Song.new(s) + if params['songs'] + params['songs'].each do |k, s| + @songs << Song.new(s) + end + end + end + + def valid? + validate! + errors.length == 0 + end + + def validate! + if @songs.length <= 0 + errors << "Du må ha med minst én låt!" end end end |