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