Module: Bandit::ViewConcerns::InstanceMethods
- Defined in:
- lib/bandit/extensions/view_concerns.rb
Instance Method Summary collapse
Instance Method Details
#bandit_choose(exp) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/bandit/extensions/view_concerns.rb', line 12 def bandit_choose(exp) name = "bandit_#{exp}".intern # choose url param with preference value = params[name].nil? ? .signed[name] : params[name] # choose with default, and set cookie .signed[name] = Bandit.get_experiment(exp).choose(value) end |
#bandit_sticky_choose(exp) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bandit/extensions/view_concerns.rb', line 22 def bandit_sticky_choose(exp) name = "bandit_#{exp}".intern # choose url param with preference value = params[name].nil? ? .signed[name] : params[name] # sticky choice may outlast a given alternative alternative = if Bandit.get_experiment(exp).alternatives.include?(value) value else Bandit.get_experiment(exp).choose(value) end # re-set cookie .permanent.signed[name] = alternative end |