Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created November 15, 2010 23:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosantoniodasilva/701163 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/701163 to your computer and use it in GitHub Desktop.
Rails 3.0.2 "visit_Foo" Arel error
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
Copy link

slbug commented Nov 16, 2010

== Default dynamic finder with an AR object
  Works using rails edge/arel edge

@carlosantoniodasilva
Copy link
Author

Yeah, they've fixed that now, in both master and 3-0. Thanks =).

@jalada
Copy link

jalada commented Nov 16, 2010

I'm suffering with this right now. Where exactly has a fix been pushed to?

@carlosantoniodasilva
Copy link
Author

rails/rails@dcdfc84

They should release Rails 3.0.3 soon with this fix, meanwhile you can bundle from 3-0-stable branch.

@jalada
Copy link

jalada commented Nov 16, 2010

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