How to List Records in Descending Order?

Hi Geo, you can do the following:

model_name.find( :all, :order => "id DESC" )

Good luck,

-Conrad

Hi, you would put this snippet of code within a controller's action.

Good luck,

-Conrad

You need to change "model_name" to your model's name (e.g., Recipe or
whatever it's called). :slight_smile:

I suggest reading some tutorials about the basics of Rails before
jumping into a Cookbook...it would help with a lot of frustrations.

--Jeremy

Hi Geo, whenever someone provides code like model_name, it shouldn't
not be implied as the actual model name. Thus, model_name in your
context is whatever model you're using to retrieve the data. In any
case, I agree with Jeremy that you should get an understanding of the
basics of Rails and you can do that by going through the "Agile Web
Development with Rails 2 Edition" (AWDwRv2) book. Finally, RoR gets
much easier when you have learned the basics and this translates into
increased productivity.

-Conrad

Hi Geo, the point of this mailing list is to help people answer and
solve development issues. However, it seems that you would benefit
yourself by simply learning the basics so that when someone provides
an answer you can understand what we are talking about. Next, in your
originally e-mail, you never provided any code so that we can properly
assist you. You simply ask the following question:

How can you list records in descending order?

Furthermore, this told me nothing about the controller and/or model
name within your Rails application. Also, you didn't provide a link
to the site that you were using to build your application. Thus, the
more information that you provide in regards to your issue the better
that we can assist you here. OK?

-Conrad

To get this post back on topic I would make the suggestion that the
logic of descending the data be a method in your model for example:

NOTE: this code sample uses Recipe as the model name.

def self.find_recipes
  find(:all, :order => "id DESC" )
end

Then in your controller when you are listing the recipes you would
just call:

@recipes = Recipe.find_recipes

Again, replace with your desired model and variable names.

Just my two cents,

- Blaine

Yes, Geo - the Model being were all your data logic should go. It's
the same thing, just more expandable later because anything using the
models logic would be changed by just changing the model.

- Blaine