如何获取最后的记录? (JS)

问题描述:

我需要得到像我的问题24-02-11(更新的desc)的最后日期时间,但通过JavaScript。我的方式不起作用,但$ time或$ all_users完美工作。如何获取最后的记录? (JS)

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, 
     resizable : false, 
     width  : 400, 
     html  : 'Last question was:' <b> + last_question + '</b>',     
       } 
....................... 
+0

btw,你为什么使用全局变量? – 2011-04-15 14:12:31

+0

嗯,我还能怎么样? – 2011-04-15 14:21:03

+0

噢,我明白了:)全局变量很难使用? – 2011-04-15 14:22:11

$last_question将返回Question对象 - 不是一个字符串。您需要从Question模型中获取特定值并将其返回。

:order => "updated_at DESC会对您的物品进行分类,但不会告诉find只返回updated_at时间。