Module: AbingoViewHelper
- Defined in:
- lib/abingo_view_helper.rb
Overview
Gives you easy syntax to use ABingo in your views.
Instance Method Summary collapse
- #ab_test(abingo, test_name, alternatives = nil, options = {}, &block) ⇒ Object
- #bingo!(abingo, test_name, options = {}) ⇒ Object
-
#include_humanizing_javascript(url = "/abingo_mark_human", style = :prototype) ⇒ Object
This causes an AJAX post against the URL.
Instance Method Details
#ab_test(abingo, test_name, alternatives = nil, options = {}, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/abingo_view_helper.rb', line 5 def ab_test(abingo, test_name, alternatives = nil, = {}, &block) if (Abingo.[:enable_specification] && !params[test_name].nil?) choice = params[test_name] elsif (Abingo.[:enable_override_in_session] && !session[test_name].nil?) choice = session[test_name] elsif (alternatives.nil?) choice = abingo.flip(test_name) else choice = abingo.test(test_name, alternatives, ) end if block content_tag = capture(choice, &block) block_called_from_erb?(block) ? concat(content_tag) : content_tag else choice end end |
#bingo!(abingo, test_name, options = {}) ⇒ Object
25 26 27 |
# File 'lib/abingo_view_helper.rb', line 25 def bingo!(abingo, test_name, = {}) abingo.bingo!(test_name, ) end |
#include_humanizing_javascript(url = "/abingo_mark_human", style = :prototype) ⇒ Object
This causes an AJAX post against the URL. That URL should call Abingo.human! This guarantees that anyone calling Abingo.human! is capable of at least minimal Javascript execution, and thus is (probably) not a robot.
31 32 33 34 35 36 37 38 39 |
# File 'lib/abingo_view_helper.rb', line 31 def include_humanizing_javascript(url = "/abingo_mark_human", style = :prototype) 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>| end |