Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 7 months ago 14
Ruby Question

Ordering model records in Rails

I am using on console:

User.all(:order => "created_at ASC")


by replacing Client with my Model User
from Rubyonrails.org, but its giving me this error:

ArgumentError: wrong number of arguments (1 for 0)


What's wrong with it?

Answer

You should use ActiveRecord#order for this goal:

User.order("created_at ASC")

or just:

User.order(:created_at)

in your case.

ActiveRecord#all method not expects any arguments.

Comments