Coder Social home page Coder Social logo

jdrew1303 / houdini-rails3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisconley/houdini-rails3

0.0 1.0 0.0 1.2 MB

Rails 3 Engine for using the Houdini Mechanical Turk API

Home Page: houdinihq.com

License: MIT License

Ruby 78.86% HTML 6.38% JavaScript 14.76%

houdini-rails3's Introduction

Overview

This ruby gem is a Rails Engine for using the Houdini Mechanical Turk API. It provides easy integration into your models and sets up the necessary controllers to receive answers posted back to your app from Houdini.

Check out the Houdini Documentation for more info about the API.

Installation (Rails 2.3.x)

Add the gem to your Gemfile

gem 'houdini-rails'

Configure a few constants in config/application.rb

config.after_initialize do
  ::Houdini::KEY = 'YOUR_API_KEY'
  ::Houdini::HOST = 'houdinihq.com' # or 'houdini-sandbox.heroku.com' for testing
  ::Houdini::RAILS_HOST = 'your_app_domain.com'
end

You may want to configure the Houdini constants differently for each of you environments.

Example Usage

Setup Houdini in your ActiveRecord model:

class Post < ActiveRecord::Base
  include Houdini::Model

  houdini :image_moderation,
    :price => '0.01',
    :title => 'Please moderate image',
    :form_template => 'app/views/houdini_templates/post.html.erb',
    :on_task_completion => :process_image_moderation_answer

  after_create :moderate_image

  def moderate_image
    Houdini.perform!(:image_moderation, self)
  end

  def process_image_moderation_answer(params)
    update_attribute(:flagged => params[:flagged])
  end
end

Create a template for the form to be sent to Mechanical Turk:

<!--app/views/houdini_templates/post.html.erb -->

<h2>Review the image for offensiveness</h2>

<h3>Instructions</h3>
<p>Please review the image below.</p>

<img src="<%= post.image_url %>"><br/>

<input type="radio" name="flagged" value="yes" class="required">
  Yes, this picture is offensive
</input>

<input type="radio" name="flagged" value="no" class="required">
  No, this picture is okay
</input>

Post.houdini class method options:

  • :price - Amount in cents you want to pay for the task to be completed
  • :title - Title that Mechanical Turk workers will see when browsing/searching available tasks
  • :form_template - ERB or HAML template used to render the form html.
  • :on_task_completion - Method that Houdini should call when the answer is posted back to your app. The results of your form will be passed into the method as the only parameter. {:flagged => 'yes'} in the example above.

houdini-rails3's People

Contributors

chrisconley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.