I’ve already do my research but I think I don’t know how to ask so I’ll try to explain…
Im looking for a way to ask for the first entry saved on a Scaffold…
Like
If I have in the table Products:
- Sweeter
- Pants
- Scarf
- Tennis
and I write @first_prod = Products.first (or something like that) on my model or in my view <%= Products.each.first %> (or something like that) Rails give me the first prouduct in this case – Sweeter…
Thanks in advance…
In rails you can define a few default ways to get the content from a model.
In your case i would create a scope.
in your model enter the following:
When you call
It will return all your products ordered by when they were created.
If you then want the very first product you just to
In the case you just want to get the item in one specific place you could do the following (instead of what i mentioned above)
Product.find(:first, :order => ‘created_at ASC’)
If my explanation is not clear, just let me know and i’ll try to refrase