Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
#6 cleaned views
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoerger committed Jul 25, 2012
1 parent 5133cbe commit c5481bc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
23 changes: 23 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,27 @@ def activate
end
redirect_to request.referer # Or use redirect_to(back)
end

def process_all_error_messages_to_string(model_name)
errors = ''

# first iterate over each field that didn't pass validations
model_name.errors.messages.each do |field|
error_temp = ''

# now iterate over each error message
field[1].each do |message|
# append error messages
if error_temp.blank?
error_temp += field.first.to_s.capitalize + ' ' + message
else
error_temp += ' and ' + message
end
end

error_temp += '. ' unless error_temp.blank? # append a period for readability
errors += error_temp # append to full error string
end
errors
end
end
21 changes: 1 addition & 20 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,7 @@ def import
next
else
# process errors!
errors = ''

# first iterate over each field that didn't pass validations
@user.errors.messages.each do |field|
error_temp = ''

# now iterate over each error message
field[1].each do |message|
# append error messages
if error_temp.blank?
error_temp += field.first.to_s.capitalize + ' ' + message
else
error_temp += ' and ' + message
end
end

error_temp += '. ' unless error_temp.blank? # append a period for readability
errors += error_temp # append to full error string
end
data << errors
data << process_all_error_messages_to_string(@user)
@users_not_added_set[user] = data
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class User < ActiveRecord::Base
:deleted_at, :requirement_ids, :user_ids, :terms_of_service_accepted,
:created_by_admin

attr_accessor(:full_query, :created_by_admin)
attr_accessor :full_query, :created_by_admin

validates :login, :presence => true,
:uniqueness => true
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table id="table_users" class="datatable table table-striped table-bordered">
<table id="table_users" class="datatable-wide table table-striped table-bordered">
<thead>
<tr>
<th>NetID</th>
Expand Down
17 changes: 10 additions & 7 deletions app/views/users/import_success.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<% title "Imported Users" %>
<%# render table of users added to the database %>
<%= render :partial => 'table', :locals => {:users => @users_added_set} %>
<% title "Import Summary" %>
<% unless @users_added_set.empty? %>
<%# render table of users added to the database %>
<h2>Users successfully imported</h2>
<%= render :partial => 'table', :locals => {:users => @users_added_set} %>
<hr />
<% end %>

<h2>Users not successfully imported</h2>

<table id="table_users" class="datatable table table-striped table-bordered">
<table id="table_users" class="datatable-wide table table-striped table-bordered">
<thead>
<tr>
<th>NetID</th>
<th>Login</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Why</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
Expand Down

0 comments on commit c5481bc

Please sign in to comment.