fixed various error messages

This commit is contained in:
Mark Moser 2016-08-01 16:43:05 -05:00
parent df6175ce86
commit 4a20c579ed
4 changed files with 12 additions and 6 deletions

View File

@ -45,7 +45,7 @@ class CandidateController < ApplicationController
def validate def validate
candidate = Candidate.find_by(test_hash: params['test_id']) candidate = Candidate.find_by(test_hash: params['test_id'])
redirect_to(root_path, alert: "Sorry, incorrect test id") and return if candidate.nil? redirect_to(root_path, flash: { error: "Sorry, incorrect test id" }) and return if candidate.nil?
session[:test_id] = candidate.test_hash session[:test_id] = candidate.test_hash
redirect_to :thankyou and return if candidate.completed? redirect_to :thankyou and return if candidate.completed?

View File

@ -10,7 +10,7 @@ class EmailFormatValidator < ActiveModel::EachValidator
end end
if results.include?(false) if results.include?(false)
record.errors[attribute] << (options[:message] || "is not formatted properly: #{value}") record.errors[attribute] << (options[:message] || "is not formatted properly")
end end
end end
end end

View File

@ -38,6 +38,10 @@
<div class="form-group"> <div class="form-group">
<label for="userid">What's your User ID?</label> <label for="userid">What's your User ID?</label>
<input type="text" id="test_id" name="test_id" required/> <input type="text" id="test_id" name="test_id" required/>
<% if flash[:error].present? %>
<div class="error"><%= flash[:error] %></div>
<% end %>
</div> </div>
<button type="submit">Begin</button> <button type="submit">Begin</button>
<% end %> <% end %>

View File

@ -4,9 +4,11 @@
<% if flash[:error].present? %> <% if flash[:error].present? %>
<div class="error"> <div class="error">
<%= flash[:error] %> <%= flash[:error] %>
<% @candidate.errors.messages.each do |k,v| %> <p>
<p><%= "#{k}: #{v}" %></p> <% @candidate.errors.messages.each do |k,v| %>
<% end %> <%= "#{k.to_s} #{v.join(' and ')}" %><br />
<% end %>
</p>
</div> </div>
<% end %> <% end %>
@ -27,6 +29,6 @@
</div> </div>
<%= form.hidden_field :quiz_id, { value: Quiz.first.to_i } %> <%= form.hidden_field :quiz_id, { value: Quiz.first.to_i } %>
<%= submit_tag "Login" %> <%= submit_tag "Save" %>
<% end %> <% end %>
</main> </main>