如何获取最后的记录? (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>',
}
.......................
答
$last_question
将返回Question
对象 - 不是一个字符串。您需要从Question
模型中获取特定值并将其返回。
:order => "updated_at DESC
会对您的物品进行分类,但不会告诉find
只返回updated_at
时间。
btw,你为什么使用全局变量? – 2011-04-15 14:12:31
嗯,我还能怎么样? – 2011-04-15 14:21:03
噢,我明白了:)全局变量很难使用? – 2011-04-15 14:22:11