Quantcast
Channel: Rails show latest entry - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Tony Fontenot for Rails show latest entry

$
0
0

Kase.first(:order => 'id DESC')

Or if you have a created_at column:

Kase.first(:order => 'created_at DESC')

There are many different ways to get what you want, and most depend on how your model is defined.

Edit:

Model:

def self.most_recent  first(:order => 'id DESC') # or whatever query you need to get the most recentend

View:

<% if Kase.most_recent %><p>Your previous kases reference was <%= Kase.most_recent.jobref %>.</p><% end %>

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>