Private method select called for class - Rails Private method select called for class - Rails ruby ruby

Private method select called for class - Rails


Based on your error message I am pretty sure your model is not an ActiveRecord Object.

If you want to make use of ActiveRecord#select, define your model like this.

class Contact < ActiveRecord::Base

Also you need to define your attributes in a database instead of via attr_reader to access them through ActiveRecord. See http://guides.rubyonrails.org/getting_started.html#running-a-migration


You seem to be using an older version of Rails, specifically version 2.3.whatever. There, the select method is indeed private on the ActiveRecord model classes (as it is inherited from the Kernel module which is part of every Ruby object and serves a wholly different purpose) and thus isn't intended to be used like it is done in Rails 3 and Rails 4.

In Rails 2.3, you can achieve similar results using this syntax:

Contact.all(:select => "DISTINCT name")

This will return an array of Contacts which have only the name attribute set.