1
试图显示包含帖子的类别列表。听起来很简单,但我有点卡住了。 这个在Rails 4中显示帖子的显示类别
ActiveRecord find all parents that have associated children
class Category < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :category
end
类似能否请您帮忙。我尝试命名的范围,但打破了应用程序。
某些原因您的解决方案不起作用 – Benjamin
噢,我很抱歉:请检查更新后的答案! –
当我在控制器上使用它的作品def show @categories = Category.where('posts_count>?',0) end – Benjamin