繁体   English   中英

无法在Rails上安装Vanity A / B测试

[英]Can't Install Vanity A/B Testing on Rails

我试图在我的Rails应用程序中安装Vanity A / B Testing ,但我什至无法从GitHub页面上获取示例。 我已经生成了虚荣模型并运行了迁移并制作了实验文件,但只要包含以下测试,

<%= ab_test :price_options %>

程序抛出错误:

invalid value for Integer(): "{:conditions=>{:experiment_id=>\"price_options\""

在我的controllers / application_controller.rb中,我只有:

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应用程序,只是为了尝试对其进行调试。 从字面上看,我所做的就是按照自述文件说明启动应用程序并安装虚荣软件,但我遇到了同样的错误。 这也发生在两台不同的机器上,所以我怀疑我很想念它,但是我不确定(否则我不会在这里!)。

编辑:从那以后,我决定改用Split gem,并且没有任何麻烦。

抛出此错误是因为当前的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'

到您的Gemfile。

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 %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM