diff options
-rw-r--r-- | lib/band.rb | 11 | ||||
-rw-r--r-- | lib/contact.rb | 2 | ||||
-rw-r--r-- | views/layout.erb | 2 |
3 files changed, 7 insertions, 8 deletions
diff --git a/lib/band.rb b/lib/band.rb index 9b949c7..dc69642 100644 --- a/lib/band.rb +++ b/lib/band.rb @@ -7,7 +7,6 @@ class Band attr_accessor :errors def initialize(params = nil) - @errors = [] @contact = Contact.new @members = "" @songs = [] @@ -31,13 +30,13 @@ class Band end def valid? - validate! - errors.length == 0 + validate! unless errors + !has_errors? end def validate! @errors = [] - + if @name.nil? || @name.strip.empty? errors << "Bandnavn mangler" end @@ -49,8 +48,8 @@ class Band end end - def has_errors - errors.length > 0 + def has_errors? + errors && errors.length > 0 end def name_and_city diff --git a/lib/contact.rb b/lib/contact.rb index d5fd267..0a7a449 100644 --- a/lib/contact.rb +++ b/lib/contact.rb @@ -17,7 +17,7 @@ class Contact end def valid? - validate! + validate! unless @errors @errors.length == 0 end diff --git a/views/layout.erb b/views/layout.erb index 9a357ff..4584662 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -7,7 +7,7 @@ <title>Påmeldingsskjema - Norsk Urskog Metal Sampler</title> </head> <body> - <% if @band && @band.has_errors %> + <% if @band && @band.has_errors? %> <div class="error"> <h1 class="error-heading">Det er feil i skjemaet!</h1> <p>Vennligst se over følgende og prøv igjen:</p> |