Permalink
Browse files

Removed the javascript from the generator as it's no longer needed.

  • Loading branch information...
1 parent 16d76a9 commit f76db64e2d4814ea1d898f2f8e5309709844ebd9 @aantix aantix committed Oct 19, 2010
Showing with 23 additions and 56 deletions.
  1. +22 −8 README.rdoc
  2. +0 −45 generators/turkee/templates/turkee.js
  3. +1 −3 generators/turkee/turkee_generator.rb
View
@@ -45,14 +45,28 @@ Run the turkee generator from your application directory to copy the needed java
rake db:migrate
-3) Change your forms to use the form helper.
- <% turkee_form_for @user do |form| %>
- <%= form.inputs %>
- <%= form.buttons %>
+3) You should disable form controls if the Turker hasn't accepted the HIT. You can determine this from your controller:
+ class SurveysController < ApplicationController
+
+ def new
+ @assignment_id = params[:assignmentId]
+ @disabled = Turkee::TurkeeFormHelper::disable_form_fields?(@assignment_id)
+ ...
+ @survey = Survey.new
+ end
+
+4) Change your forms to use the form helper.
+ <% turkee_form_for(@survey, @assignment_id) do |f| %>
+ <%= f.hidden_field :turkee_task_id, :value => @turkee_task.id %>
+ <%= f.hidden_field :parent_id, :value => @turkee_task.parent_id %>
+
+ <p><%= f.text_area :value, :disabled => @disabled %></p>
+ <p><%= f.submit 'Create', :disabled => @disabled %></p>
<% end %>
+
Using the turkee_form_for helper will post the form to the Mechanical Turk sandbox if you're in development/test mode, otherwise it will be posted to Mechanical Turk production/live site.
-4) Run the following rake task to post to Mechanical Turk :
+5) Run the following rake task to post to Mechanical Turk :
# Title of your HIT
# Description of your HIT
# Model name of your task form (the New action should be implemented)
@@ -65,9 +79,9 @@ Using the turkee_form_for helper will post the form to the Mechanical Turk sandb
e.g. :
rake turkee:posthit ["Please complete our survey", "Tell us your favorite color.", "Survey", 100, 0.05, 2]
-5) Allow some time for the "Turkers" to respond to your HIT.
+6) Allow some time for the "Turkers" to respond to your HIT.
-6) Run the rake task that retrieves the values from Mechanical Turk and stores the user entered values into your model.
+7) Run the rake task that retrieves the values from Mechanical Turk and stores the user entered values into your model.
rake turkee::getresults
Rerun this task periodically to retrieve newly entered form values. You can setup this task as a cronjob to automate this.
@@ -78,7 +92,7 @@ Rerun this task periodically to retrieve newly entered form values. You can set
*/5 * * * * cd /var/www/your/turk/application && rake turkee:getresults
-7) When a response is retrieved from Mechanical Turk, Turkee attempts to create a data row for the model specified using the corresponding retrieved data. If the row cannot be created (input failed model validations), the assignment is rejected.
+8) When a response is retrieved from Mechanical Turk, Turkee attempts to create a data row for the model specified using the corresponding retrieved data. If the row cannot be created (input failed model validations), the assignment is rejected.
As for Mechanical Turk approval, if the row is created and you haven't specified your own custom approve? method for the model, the assignment will automatically be approved. If you'd like to add your own custom approval method, add the approve? instance method to your model. E.g. :
class Survey < ActiveRecord::Base
def approve?
@@ -1,45 +0,0 @@
-// Javascript referenced from the rturk example.
-
-// Initializes a mechanical turk form and disables the form button
-// until the user has accepted the turk task.
-
-function gup( name )
-{
- var regexS = "[\\?&]"+name+"=([^&#]*)";
- var regex = new RegExp( regexS );
- var tmpURL = window.location.href;
- var results = regex.exec( tmpURL );
- if( results == null )
- return "";
- else
- return results[1];
-}
-
-//
-// This method decodes the query parameters that were URL-encoded
-//
-function decode(strToDecode)
-{
- var encoded = strToDecode;
- return unescape(encoded.replace(/\+/g, " "));
-}
-
-function mturk_form_init(obj_name)
-{
- document.getElementById('assignmentId').value = gup('assignmentId');
-
- //
- // Check if the worker is PREVIEWING the HIT or if they've ACCEPTED the HIT
- //
- if (gup('assignmentId') == "ASSIGNMENT_ID_NOT_AVAILABLE")
- {
- // If we're previewing, disable the button and give it a helpful message
- document.getElementById(obj_name + '_submit').disabled = true;
- document.getElementById(obj_name + '_submit').value = "You must ACCEPT the HIT before you can submit the results.";
- } else {
- var form = document.getElementById('mturk_form');
- if (document.referrer && ( document.referrer.indexOf('workersandbox') != -1) ) {
- form.action = "https://workersandbox.mturk.com/mturk/externalSubmit";
- }
- }
-}
@@ -2,16 +2,14 @@ class TurkeeGenerator < Rails::Generator::Base
def manifest
record do |m|
- m.directory File.join('public', 'javascripts')
- m.template 'turkee.js', File.join('public', 'javascripts', 'turkee.js')
m.migration_template "turkee_migration.rb.erb", File.join('db', 'migrate'), :migration_file_name => 'create_turkee_tasks'
m.sleep 1 # Need this sleep so that we don't get the same migration timestamp for both migrations
m.migration_template "turkee_imported_assignments.rb.erb", File.join('db', 'migrate'), :migration_file_name => 'create_turkee_imported_assignments'
end
end
def banner
- %{Usage: #{$0} #{spec.name}\nCopies turkee.js to public/javascripts/ and generates needed migrations.}
+ %{Usage: #{$0} #{spec.name}\nCopies needed migrations to project.}
end
end

0 comments on commit f76db64

Please sign in to comment.