Module: Turkee::TurkeeFormHelper
- Defined in:
- lib/turkee.rb
Class Method Summary collapse
-
.disable_form_fields?(assignment) ⇒ Boolean
Returns whether the form fields should be disabled or not (based on the assignment_id).
Instance Method Summary collapse
-
#mturk_url ⇒ Object
Returns the external Mechanical Turk url used to post form data based on whether RTurk is cofigured for sandbox use or not.
-
#turkee_form_for(record, params, options = {}, &proc) ⇒ Object
Rails 3.1.1 form_for implementation with the exception of the form action url will always point to the Amazon externalSubmit interface and you must pass in the assignment_id parameter.
Class Method Details
.disable_form_fields?(assignment) ⇒ Boolean
Returns whether the form fields should be disabled or not (based on the assignment_id)
313 314 315 316 |
# File 'lib/turkee.rb', line 313 def self.disable_form_fields?(assignment) assignment_id = assignment.is_a?(Hash) ? assignment[:assignmentId] : assignment (assignment_id.nil? || assignment_id == 'ASSIGNMENT_ID_NOT_AVAILABLE') end |
Instance Method Details
#mturk_url ⇒ Object
Returns the external Mechanical Turk url used to post form data based on whether RTurk is cofigured
for sandbox use or not.
308 309 310 |
# File 'lib/turkee.rb', line 308 def mturk_url RTurk.sandbox? ? "https://workersandbox.mturk.com/mturk/externalSubmit" : "https://www.mturk.com/mturk/externalSubmit" end |
#turkee_form_for(record, params, options = {}, &proc) ⇒ Object
Rails 3.1.1 form_for implementation with the exception of the form action url will always point to the Amazon externalSubmit interface and you must pass in the assignment_id parameter.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/turkee.rb', line 272 def turkee_form_for(record, params, = {}, &proc) raise ArgumentError, "Missing block" unless block_given? raise ArgumentError, "turkee_form_for now requires that you pass in the entire params hash, instead of just the assignmentId value. " unless params.is_a?(Hash) [:html] ||= {} case record when String, Symbol object_name = record object = nil else object = record.is_a?(Array) ? record.last : record object_name = [:as] || ActiveModel::Naming.param_key(object) (record, ) end [:html][:remote] = .delete(:remote) if .has_key?(:remote) [:html][:method] = .delete(:method) if .has_key?(:method) [:html][:authenticity_token] = .delete(:authenticity_token) builder = [:parent_builder] = instantiate_builder(object_name, object, , &proc) fields_for = fields_for(object_name, object, , &proc) = builder.multipart? ? { :multipart => true } : {} output = form_tag(mturk_url, .merge!(.delete(:html))) params.each do |k,v| unless k =~ /^action$/i || k =~ /^controller$/i || v.class != String output.safe_concat("<input type=\"hidden\" id=\"#{k}\" name=\"#{CGI.escape(k)}\" value=\"#{CGI.escape(v)}\"/>") end end [:disabled] = true if params[:assignmentId].nil? || Turkee::TurkeeFormHelper::disable_form_fields?(params[:assignmentId]) output << fields_for output.safe_concat('</form>') end |