简体   繁体   English

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

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

I'm trying to install Vanity A/B Testing in my Rails App, but I can't even get the example from the GitHub page working. 我试图在我的Rails应用程序中安装Vanity A / B Testing ,但我什至无法从GitHub页面上获取示例。 I've generated the vanity models and run the migrations and made the experiment files, but as soon as I include a test like 我已经生成了虚荣模型并运行了迁移并制作了实验文件,但只要包含以下测试,

<%= ab_test :price_options %>

the program throws an error: 程序抛出错误:

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

In my controllers/application_controller.rb I have just: 在我的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

I didn't include a user identifier because I haven't built one into this app yet, but the Vanity docs say that if no argument is supplied Vanity will just use cookies instead, so that shouldn't be an issue. 我没有包括用户标识符,因为我尚未在该应用程序中内置一个用户标识符,但是Vanity文档说如果不提供任何参数,Vanity只会使用Cookie,因此这不成问题。 If anyone has any clue why this cryptic error is being thrown, I would be very appreciative! 如果有人知道为什么会引发此神秘错误,我将不胜感激!

Edit: I should add that I actually started a new rails app from scratch just to try and debug this. 编辑:我应该补充一点,我实际上是从头开始启动一个新的Rails应用程序,只是为了尝试对其进行调试。 Literally all I did was start an app and install vanity following the readme instructions and I got this same error. 从字面上看,我所做的就是按照自述文件说明启动应用程序并安装虚荣软件,但我遇到了同样的错误。 This has happened on two different machines as well, so I suspect it's something obvious that I'm missing, but I can't be sure (else I wouldn't be here!). 这也发生在两台不同的机器上,所以我怀疑我很想念它,但是我不确定(否则我不会在这里!)。

EDIT: I've since decided to use the Split gem instead, and am having no troubles with it. 编辑:从那以后,我决定改用Split gem,并且没有任何麻烦。

This error is thrown because the current release version of Vanity uses the deprecated Rails find(:first) method, specifically: 抛出此错误是因为当前的Vanity发行版使用了不赞成使用的Rails find(:first)方法,特别是:

 VanityParticipant.first(:conditions=>{ :experiment_id=>experiment.to_s, :identity=>identity.to_s })

This no longer works with Rails 4.1 but is fixed in the master branch of Vanity, so you can get round this in your Rails 4.1 app by adding: 这不再适用于Rails 4.1,但已在Vanity的主分支中修复,因此您可以通过添加以下内容在Rails 4.1应用程序中解决此问题:

gem 'vanity', :git => 'git@github.com:assaf/vanity', :branch => 'master'

to your Gemfile. 到您的Gemfile。

With

class ApplicationController < ActionController::Base
  protect_from_forgery
  use_vanity
end

and

# 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

and

class StaticController < ApplicationController
  def home
  end
end

the following view loads and sets a vanity_id cookie: 以下视图加载并设置了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