How to get last record? (JS)
I need to get last date time like 24-02-11 (updated desc) of my question but through JavaScript. My way doesnt work, but $time or $all_users working perfectly.
my_controller
$all_users = User.count('id')
$last_question = Question.find(:last, :order => "updated_at DESC", :limit => 1)
$time = Time.now.strftime("%d %B, %Y")
my_layout_view
<% javascript_tag do %>
Ext.BLANK_IMAGE_URL = '<%= image_path '/ext/resources/images/default/s.gif' %>';
<%= "time = \"#{$time}\"" %>;
<%= "last_question = \"#{$last_question}\"" %>;
<% end %>
my_view
..........
items : [
{
region : 'north',
minWidth : 75,
height : 35,
maxWidth : 150,
collapsible : false开发者_如何学Python,
resizable : false,
width : 400,
html : 'Last question was:' <b> + last_question + '</b>',
}
.......................
$last_question
would return a Question
object - not a string. You need to get a specific value from your Question
model and return it.
:order => "updated_at DESC
will sort your items, but doesn't tell the find
to only return the updated_at
time.
精彩评论