Skip to content

Commit

Permalink
Clear DB and Export to CSV, Bug Fix for intructions
Browse files Browse the repository at this point in the history
  • Loading branch information
rposborne committed Apr 18, 2011
1 parent 6d1391b commit f224159
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -12,7 +12,7 @@ gem "hpricot", "0.8.3", :group => :development
gem "ruby_parser", "2.0.5", :group => :development
gem "jquery-rails"
gem "rspec-rails", ">= 2.0.1", :group => [:development, :test]

gem "fastercsv"
group :development, :test do
gem 'web-app-theme', '>= 0.6.2'
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -34,6 +34,7 @@ GEM
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
fastercsv (1.5.4)
haml (3.0.25)
haml-rails (0.3.4)
actionpack (~> 3.0)
Expand Down Expand Up @@ -108,6 +109,7 @@ PLATFORMS
ruby

DEPENDENCIES
fastercsv
haml
haml-rails
heroku
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/responses_controller.rb
Expand Up @@ -37,6 +37,31 @@ def new
def edit
@response = Response.find(params[:id])
end

def empty
Response.delete_all
@responses = []
render :index
end

def export_to_csv
@responses = Response.find(:all)

csv_string = FasterCSV.generate do |csv|
# header row
csv << ["id", "participant_id", "group", "error", "essay", "Correct?", "Field Before Correction", "Time Corrected"]

# data rows
@responses.each do |response|
csv << [response.id, response.user_id, response.user.group,response.error, response.essay, response.correct, response.uncorrected, response.created_at ]
end
end

# send it to the browsah
send_data csv_string,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=responses.csv"
end

# POST /responses
# POST /responses.xml
Expand Down
2 changes: 1 addition & 1 deletion app/views/essays/index.haml
Expand Up @@ -54,7 +54,7 @@
.instruction_body
%p
Please wait.
Please wait.
-# shown prompting us to finish or not, when we click finish
.confirm_quit
Expand Down
6 changes: 3 additions & 3 deletions app/views/responses/_sidebar.html.erb
Expand Up @@ -5,9 +5,9 @@
</div>
</div>
<div class="block">
<h3>Links</h3>
<h3>Actions</h3>
<ul class="navigation">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><%= link_to "Clear All Responses", responses_empty_path, :confirm => "#{t("web-app-theme.confirm", :default => "Are you sure?")}" %></li>
<li><%= link_to "Export To CSV", responses_export_path %></li>
</ul>
</div>
7 changes: 5 additions & 2 deletions config/routes.rb
@@ -1,5 +1,5 @@
PhdChecker::Application.routes.draw do
resources :responses


match 'a/score_card' => 'a#score_card'
match 'b/score_card' => 'b#score_card'
Expand All @@ -14,7 +14,10 @@
resources :d
resources :e
resources :f

match 'responses/empty' => "responses#empty"
match 'responses/export' => "responses#export_to_csv"
resources :responses

match 'users/stats' => 'users#stats'
resources :users
root :to => "a#index"
Expand Down

0 comments on commit f224159

Please sign in to comment.