Module: Abongo::ViewHelper
- Defined in:
- lib/abongo/view_helper.rb
Instance Method Summary collapse
- #ab_test(test_name, alternatives = nil, options = {}, &block) ⇒ Object
- #bongo!(test_name, options = {}) ⇒ Object
-
#include_humanizing_javascript(url = "/abongo_mark_human", style = :prototype) ⇒ Object
This causes an AJAX post against the URL.
Instance Method Details
#ab_test(test_name, alternatives = nil, options = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/abongo/view_helper.rb', line 6 def ab_test(test_name, alternatives = nil, = {}, &block) if (Abongo.[:enable_specification] && !params[test_name].nil?) choice = params[test_name] elsif (Abongo.[:enable_override_in_session] && !session[test_name].nil?) choice = session[test_name] elsif (Abongo.[:enable_selection] && !params[test_name].nil?) choice = Abongo.parse_alternatives(alternatives)[params[test_name].to_i] elsif (alternatives.nil?) begin choice = Abongo.flip(test_name, ) rescue if Abongo.[:failsafe] choice = true else raise end end else begin choice = Abongo.test(test_name, alternatives, ) rescue if Abongo.[:failsafe] choice = Abongo.parse_alternatives(alternatives).first else raise end end end if block content_tag = capture(choice, &block) Rails::VERSION::MAJOR <= 2 and block_called_from_erb?(block) ? concat(content_tag) : content_tag else choice end end |
#bongo!(test_name, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/abongo/view_helper.rb', line 44 def bongo!(test_name, = {}) begin Abongo.bongo!(test_name, ) rescue if Abongo.[:failsafe] return else raise end end end |
#include_humanizing_javascript(url = "/abongo_mark_human", style = :prototype) ⇒ Object
This causes an AJAX post against the URL. That URL should call Abongo.human! This guarantees that anyone calling Abongo.human! is capable of at least minimal Javascript execution, and thus is (probably) not a robot.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/abongo/view_helper.rb', line 58 def include_humanizing_javascript(url = "/abongo_mark_human", style = :prototype) begin return if Abongo.is_human? rescue if Abongo.[:failsafe] else raise end end script = nil if (style == :prototype) script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=new Ajax.Request('#{url}', {parameters:{a: a, b: b, c: a+b}})" elsif (style == :jquery) script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=jQuery.post('#{url}', {a: a, b: b, c: a+b})" end script.nil? ? "" : %Q|<script type="text/javascript">#{script}</script>|.html_safe end |