ruby on rails - Getting a max/min date value from an associated model -



ruby on rails - Getting a max/min date value from an associated model -

rails 2.3.5

below, (tickets :have_many => logs), i'm listing 'created_at' value of index 0. i'd max & min values field (saying 'first log 07-01-2011, lastly log entry 07-18-2011')

<% @tickets.each |t| %> <% if !t.log_entries[0].nil? %> <%= t.log_entries[0].created_at %> <% end %> <% end %> <% end %>

is there easy way this? tried playing around max couldn't figure out working syntax. other thing can thing of find_first asc & desc query in view.

thanks !

you can rails subquery:

<%= @ticket.log_entries.find(:first, :order => "created_at asc").created_at.to_s %> <%= @ticket.log_entries.find(:first, :order => "created_at desc").created_at.to_s %>

happy coding :)

ruby-on-rails

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -