Skip to content

Instantly share code, notes, and snippets.

@raarellano
Created September 8, 2014 20:28
Show Gist options
  • Save raarellano/76b0ade01d8bb4747cb1 to your computer and use it in GitHub Desktop.
Save raarellano/76b0ade01d8bb4747cb1 to your computer and use it in GitHub Desktop.
Export to Excel
def participants_export
@model_template = @survey.model_template
@categories = @model_template.categories.wout_overall
@sub_categories = @model_template.sub_categories
#Users + Scores
if params[:start_date] && params[:end_date]
@start_date_searched = params[:start_date].to_s
@start_date = Date.parse(@start_date_searched)
@end_date_searched = params[:end_date].to_s
@end_date = Date.parse(@end_date_searched)
else
@start_date = Date.today.beginning_of_week
@end_date = Date.today.end_of_week
end
@users = @survey.users
@assessments = @survey.assessments.by_date_created(@start_date, @end_date)
respond_to do |format|
format.xls
end
end
match "surveys/:id/participants_export" => "surveys#participants_export", :as => :participants_export, via: :get
<table>
<thead>
<tr>
<th>ID</th>
<th>Assessment ID</th>
<th>Completed</th>
<th>Name</th>
<th>Email</th>
<th>Title</th>
<th>Company</th>
<th>Company Culture</th>
<th>Company Orginizational Culture</th>
<th>Region</th>
<th>Company Size in Revenues</th>
<th>Position</th>
<th>Industry</th>
<th>Overall Score</th>
<% @categories.each do |category| %>
<th><%= category.title %></th>
<% end %>
<% @sub_categories.each do |sub_category| %>
<th><%= sub_category.title %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @assessments.each do |assessment|%>
<tr>
<td><%= assessment.user.id %></td>
<td><%= assessment.id %></td>
<td>
<% if assessment.submit_date != nil %>
<%= assessment.submit_date.strftime("%m/%d/%y") %>
<% else %>
Not Completed
<% end %>
</td>
<td><%= assessment.user %></td>
<td><%= assessment.user.email %></td>
<td><%= assessment.user.title %></td>
<td><%= assessment.user.company %></td>
<td><%= assessment.user.company_culture %></td>
<td><%= assessment.user.company_org_structure %></td>
<td><%= assessment.user.region %></td>
<td><%= assessment.user.company_size_revenue %></td>
<td><%= assessment.user.position %></td>
<td><%= assessment.user.industry %></td>
<% if assessment.submit_date != nil && assessment.submit_date != "" %>
<td><%= assessment.overall_score.round(2) %></td>
<% @categories.each do |category| %>
<td><%= category.score(assessment) %></td>
<% end %>
<% @sub_categories.each do |sub_category| %>
<td><%= sub_category.score(assessment) %></td>
<% end %>
<% end %>
</tr>
<% end %>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment