I have searched and searched, but cannot find an answer to this simple
question:
How can you list records in descending order?
I have the cookbook example loaded, but can't seem to list the recipes
in reverse order (by the primary key - id).
Thanks ahead of time for any and all help.
--
Posted via http://www.ruby-forum.com/.
model_name.find( :all, :order => "id DESC" )
Good luck,
-Conrad
Thanks, but where do I put that line of code? Model? Controller? View?
And where was model_name defined?
Good luck,
-Conrad
On 4/1/07, Geo Pappas <rails-mai...@andreas-s.net> wrote:
>
If I put that line in the controller, I get the following error:
undefined local variable or method `model_name' for
RecipeController:Class
I suggest reading some tutorials about the basics of Rails before
jumping into a Cookbook...it would help with a lot of frustrations.
--Jeremy
On 4/1/07, Geo Pappas <rails-mai...@andreas-s.net> wrote:
>
--
http://www.jeremymcanally.com/
My free Ruby e-book:
http://www.humblelittlerubybook.com/book/
My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
That is what I was thinking, but the poster didn't state that nor did
they post it in a way that signified that. For example, the following
is the "normal" way that I am used to seeing something like that:
<model_name>.find( :all, :order => "id DESC" )
Also, since RoR hides most of the "code" behind the scenes, it is hard
to know exactly what has been defined and what hasn't.
> I suggest reading some tutorials about the basics of Rails before
> jumping into a Cookbook...it would help with a lot of frustrations.
>
> --Jeremy
There don't seem to be many tutorials on the web (at least that I could
find), but I have read every tutorial that I could find (multiple
times). Do you have any that you recommend?
I have also searched multiple forums to no avail. That is why I am
posting the question here.
I felt that this should be a relatively easy thing to do, but have spent
way too much time on this (especially when people tout how easy RoR is).
-Conrad
On 4/1/07, Geo Pappas <rails-mai...@andreas-s.net> wrote:
>
While I appreciate you taking the time to answer my question, it was
only partially-answered. You gave me a snippet of code without telling
me where it was supposed to go. On top of that, some of the "code"
wasn't even code.
And finally, even if I replace model_name with Recipe, it still doesn't
work.
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
On 4/1/07, Geo Pappas <rails-mai...@andreas-s.net> wrote:
>
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
On Apr 1, 10:07 pm, "Conrad Taylor" <conra...@gmail.com> wrote:
> 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
>
> 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:
Thanks for your response.
I thought that I did provide enough information. In my original email,
I stated "I have the cookbook example loaded, but can't seem to list the
recipes in reverse order (by the primary key - id)."
I figured that everyone has the cookbook example, so didn't think that I
needed to provide any code snippets. Next time I will.
Thanks for your help. I have been able to take your pseudo-code snippet
and figure out the rest.
blaine:
Thanks for your suggestion. It look like another way of doing the same
thing that Conrad was suggesting, except it defines another method in
the model.
- Blaine
On Apr 2, 7:17 am, Geo Pappas <rails-mailing-l...@andreas-s.net>
wrote: