Skip to content
Blurring the line between Mechanical Turk, Rails and usability testing..
Ruby Other
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Turkee simplifies the process of posting and retrieving HIT (Human Intelligence Task) data from Amazon's Mechanical Turk.

Forms are created using a simple form helper. HITs are created by issuing a rake command. Retrieving form data from Amazon requires just one more rake command.


Make sure that the rturk gem is installed, referenced in your environment.rb :

config.gem 'rturk'

…and configured with your Amazon Turk credentials. I created a config/initializers/turk_task_config.rb file with the following in it:


RTurk::logger.level     = Logger::DEBUG
RTurk.setup(AWSACCESSKEYID, AWSACCESSKEY, :sandbox => (Rails.env == 'production' ? false : true))


Install the Turkee gem:

sudo gem install turkee

And add it to your environment.rb configuration as a gem dependency:

config.gem 'turkee'

To access the Turkee rake tasks, add the following to your application's Rakefile:

require 'tasks/turkee'

Run the turkee generator from your application directory to copy the needed javascript file and migrations into your application:

./script/generate turkee    # Rails 2
## Support for Rails 3 in the future.


1) Add 'turkee' to your javascript includes in your application.html.erb

 <%= javascript_include_tag :defaults, :turkee %>
* Turkee requires the default Rails javascript libraries, so be sure you are including those as well (as show above with :defaults).

2) Run your migrations :

rake db:migrate

3) Change your forms to use the form helper.

<% turkee_form_for @user do |form| %>
    <%= form.inputs %>
    <%= form.buttons %>
<% 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 :

# Title of your HIT
# Description of your HIT
# Model name of your task form (the New action should be implemented)
# Number of assignments for HIT
# The reward for a successful completion
# The lifetime of the HIT in days (e.g. 5 days)

rake turkee:posthit[<Title>, <Description>, <Model>, <Number of Assignments>, <Reward>, <Lifetime>]

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) 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.

crontab -e

# E.g. run every five minutes
*/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. 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?
    (!response.blank? && !comment.blank?)


Copyright © 2010 Jim Jones. See LICENSE for details.

Something went wrong with that request. Please try again.