我试图在我的Rails应用程序中安装虚荣A/B测试,但我甚至无法从GitHub页面获得这个示例。我已经生成了虚荣心模型,运行了迁移,并创建了实验文件,但是一旦我包括了一个测试,比如
<%= ab_test :price_options %>程序抛出一个错误:
invalid value for Integer(): "{:conditions=>{:experiment_id=>\"price_options\""在我的控制器/应用程序_控制器. In中,我只有:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
use_vanity
end我没有包含一个用户标识符,因为我还没有在这个应用程序中内置一个标识符,但是Vanity文档说,如果没有提供任何参数,Vanity将只使用cookie,所以这不应该是一个问题。如果有人知道为什么这个神秘的错误被抛出,我会非常感激!
编辑:我应该补充说,我实际上是从零开始启动一个新的rails应用程序,只是为了尝试调试这个应用程序。实际上,我所做的就是按照自述指令启动一个应用程序并安装虚荣心,我也得到了同样的错误。这种情况也发生在两台不同的机器上,所以我怀疑这显然是我丢失的东西,但我不能确定(否则我就不会在这里了!)
编辑:我已经决定使用分割宝石代替,并没有问题,它。
发布于 2014-06-18 13:07:15
引发此错误是因为Vanity的当前发行版使用了废弃的Rails find(:first)方法,具体而言:
VanityParticipant.first(:conditions=>{ :experiment_id=>experiment.to_s, :identity=>identity.to_s })这不再适用于Rails 4.1,而是固定在Vanity的主分支中,因此您可以在Rails 4.1应用程序中添加:
gem 'vanity', :git => 'git@github.com:assaf/vanity', :branch => 'master'寄给你的档案。
发布于 2014-06-10 02:48:51
使用
class ApplicationController < ActionController::Base
protect_from_forgery
use_vanity
end和
# experiments/price_options.rb
ab_test "Price options" do
description "Mirror, mirror on the wall, who's the best price of all?"
alternatives(19, 25, 29)
end和
class StaticController < ApplicationController
def home
end
end以下视图加载并设置一个vanity_id cookie:
<h1>Static#home</h1>
<p>Find me in app/views/static/home.html.erb</p>
<h2>Get started for only $<%= ab_test :price_options %> a month!</h2>
<%= link_to 'Make a new account', new_account_path %>https://stackoverflow.com/questions/24029838
复制相似问题