to_s :db

I think I have rails 1.2 installed (>> Successfully installed
rails-1.1.6.5618), but I don't seem to be able to use to_s(:db)

eg

User.find_all.to_s(:db)

ArgumentError: wrong number of arguments (1 for 0)
        from (irb):19:in `to_s'
        from (irb):19

I was expecting "1,2,3,4"

Dano wrote:

I think I have rails 1.2 installed (>> Successfully installed
rails-1.1.6.5618), but I don't seem to be able to use to_s(:db)

As far as I know, .to_s(:db) is only available for Time formatting.

Time.now.to_s(:db) #=> "2006-12-29 21:36:20"

See Time::DATE_FORMATS for more.

-Dan Manges

Dano wrote:

>> User.find_all.to_s(:db)
ArgumentError: wrong number of arguments (1 for 0)
        from (irb):19:in `to_s'
        from (irb):19

I was expecting "1,2,3,4"

You could implement this in Rails as:
User.find(:all).map(&:id).join(",")

map(&:id) will create an array of id's for the users, and join(",")
will join them in a string with commas.

If you're looking to do .to_s(:db) to use this in an IN clause of a
database query, Rails will automatically do that with query bind
parameters:

Finding all the users by their own IDs:

all_user_ids = User.find(:all).map(&:id)
Rails 1.1.6: User.find(:all, :conditions => ["id IN (?)",
all_user_ids])
Rails 1.2.0: User.find(:all, :conditions => {:id => all_user_ids})

-Dan Manges