Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 根据上次发布时创建的主题列表对主题列表进行排序_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 根据上次发布时创建的主题列表对主题列表进行排序

Ruby on rails 根据上次发布时创建的主题列表对主题列表进行排序,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,制作论坛应用程序 class Topic < ActiveRecord::Base belongs_to :user belongs_to :board has_many :posts, :inverse_of => :topic end class Post < ActiveRecord::Base belongs_to :user belongs_to :topic, :inverse_of => :posts end 查看董事会时,我希望主题

制作论坛应用程序

class Topic < ActiveRecord::Base
  belongs_to :user
  belongs_to :board
  has_many :posts, :inverse_of => :topic
end

class Post < ActiveRecord::Base
  belongs_to :user
  belongs_to :topic, :inverse_of => :posts
end
查看董事会时,我希望主题列表按照上次帖子创建日期的主题顺序排列。但是,我不知道如何以order方法可以理解的方式来编写

理想情况下,它会像这样简单

@topics=@board.topics.ordertopic.posts.last.created\u位于

我写的任何内容都会返回关于不存在列的错误

需要注意的一点是,@topics将被输入paginate,因此我不能简单地提取@board.topics的结果,自己排序,然后再进行paginate,因为paginate需要特定类型的集合

始终附加错误消息。 使用排序:

@topics=@board.topics.sort{t|t.posts.last.created_at}


您的方法返回了一个错误:缓存0.1ms SELECT posts.*来自posts.topic_id=?ORDER BY posts.id DESC LIMIT 1[[topic_id,3]]***ArgumentError异常:将ActiveSupport::TimeWithZone与0进行比较也失败,我已经尝试过类似的操作,但它不起作用,因为一旦排序,对结果排序列表进行分页会导致以下错误:**NoMethodError异常:`的未定义方法paginate'。由于此错误,请尝试在控制器中添加require'will_paginate/array'