Catmal Catmal - 1 year ago 57
MySQL Question

Rails show latest value after grouping

If I have this database table servers:

date, server_id, server_name, server_status

I have set in my controller:

@servers =

And assuming in my view I have a table like:

<% @servers.each do |server| %>

<td><%= server.server_name %></td>

<td><%= server.server_status %></td>

How do I show the server status at the most recent date recorded?

Answer Source
@servers = Server.order(created_at: :desc).group(:server_id)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download