Ad.minimum(:views)
must work
You can add additional restrictions, for example:
Ad.where(:user_id => 12345).minimum(:views)
To find only add by user with id 12345
btw: You can easily test such things in the rails console (just type "rails c" from the command line) One thing that often helps me is simply to get the result class of some operation.
If you enter something like:
@foo = Add.all
And then:
@foo.class
You will see that @foo is an array that, of course, knows nothing about ActiveRecord # minimum
thorsten mΓΌller
source share