Created
November 15, 2010 23:21
-
-
Save carlosantoniodasilva/701163 to your computer and use it in GitHub Desktop.
Rails 3.0.2 "visit_Foo" Arel error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sqlite3' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlite3', :database => ':memory:' | |
) | |
ActiveRecord::Schema.define(:version => 0) do | |
create_table :users, :force => true do |t| | |
t.string :name | |
end | |
end | |
class User < ActiveRecord::Base | |
def to_s; name; end | |
end | |
def execute | |
puts yield rescue puts "- #{$!}" | |
end | |
aaron = User.create!(:name => 'Aaron') | |
carlos = User.create!(:name => 'Carlos') | |
santiago = User.create!(:name => 'Santiago') | |
puts "== Default finder, only one record given" | |
execute { User.find(aaron) } | |
# OK => Aaron | |
execute { User.find([aaron.id]) } | |
# OK => Aaron | |
execute { User.find([aaron]) } | |
# OK => Aaron | |
puts "== Default finder, but multiple records" | |
execute { User.find([aaron, carlos, santiago]) } | |
# arel-2.0.2/lib/arel/visitors/visitor.rb:15:in `send': undefined method `visit_User' for #<Arel::Visitors::SQLite:0x1010a9248> (NoMethodError) | |
# Here is another example that raises the same error (and it worked pretty much ok using Rails 2.3.x) | |
puts "== Default dynamic finder" | |
execute { User.find_by_id(carlos.id) } | |
# OK => Carlos | |
# These examples would be better explained with associations (think about Post.find_by_author_id) | |
puts "== Default dynamic finder with an AR object" | |
execute { User.find_by_id(carlos) } | |
# arel-2.0.2/lib/arel/visitors/visitor.rb:15:in `send': undefined method `visit_User' for #<Arel::Visitors::SQLite:0x1010a9068> (NoMethodError) | |
## Rails 2.3.10 output | |
# == Default finder, only one record given | |
# Aaron | |
# Aaron | |
# Aaron | |
# == Default finder, but multiple records | |
# Aaron | |
# Carlos | |
# Santiago | |
# == Default dynamic finder | |
# Carlos | |
# == Default dynamic finder with an AR object | |
# Carlos | |
## Rails 3.0.2 output | |
# == Default finder, only one record given | |
# Aaron | |
# Aaron | |
# Aaron | |
# == Default finder, but multiple records | |
# - undefined method `visit_User' for #<Arel::Visitors::SQLite:0x10194c0a8> | |
# == Default dynamic finder | |
# Carlos | |
# == Default dynamic finder with an AR object | |
# - undefined method `visit_User' for #<Arel::Visitors::SQLite:0x10194c0a8> |
slbug
commented
Nov 16, 2010
Yeah, they've fixed that now, in both master and 3-0. Thanks =).
I'm suffering with this right now. Where exactly has a fix been pushed to?
They should release Rails 3.0.3 soon with this fix, meanwhile you can bundle from 3-0-stable branch.
Fixed it by rolling back to 3.0.1 for now. Setting the branch to 3-0-stable didn't seem to help. I'll wait for 3.0.3.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment