Search code examples
mysqlruby-on-railsactiverecordredisvanity

Vanity not works with MySql


I tried to install Vanity gem for my rails 2.3.5 application and I want to use MySQL for vanity. Everything is working great when I configure it with redis but when I change the config file to use mysql :

development:
  adapter: active_record
  active_record_adapter: mysql
  host: localhost
  database: vanity
  username: root
  password:

I get the following error :

Showing
/Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_ab_test.erb where line #1 raised:

Vanity::Adapters::ActiveRecordAdapter is not missing constant
VanityConversion! Extracted source (around line #1):

1: <% score = experiment.score %> 
2: <table> 
3:   <caption> 
4:     <%= experiment.conclusion(score).join(" ") %></caption> 

Trace of template
inclusion:
/Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_experiment.erb,
/Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_experiments.erb,
/Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_report.erb

I added in environment file development.rb :

Vanity.playground.establish_connection :development
Vanity.playground.collecting = true

So it has to do something with the adapter included in the vanity gem, because redis is working perfect. Somebody who knows a solution?


Solution

  • I haven't figured out the cause for this yet, but I got it to work by being more explicit with the class names for the has_many associations in the active_record_adapter.rb file:

    has_many :vanity_metric_values, :class_name => "Vanity::Adapters::ActiveRecordAdapter::VanityMetricValue"
    has_many :vanity_conversions, :dependent => :destroy, :class_name => "Vanity::Adapters::ActiveRecordAdapter::VanityConversion"
    

    Edit: This seems to break the migration process when booting up vanity for the first time (which I'm working to fix!), but may help you on your way to a solution.