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

时间:2011-04-15 13:54:12

标签: ruby-on-rails

我需要获得我的问题的最后一次约会时间,例如24-02-11(更新的desc),但是通过JavaScript。我的方式不起作用,但$ time或$ all_users工作得很好。

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>',                 
                }
.......................

1 个答案:

答案 0 :(得分:1)

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

:order => "updated_at DESC会对您的商品进行排序,但不会告诉find仅返回updated_at时间。

相关问题