-1
我有一個簡單的博客網站,並試圖從特定類別檢索帖子。我已經將模型設置如下。如何在Ruby on Rails中顯示特定類別的帖子
class Post < ActiveRecord::Base
has_many :categorizations
has_many :categories, through: :categorizations
attr_accessible :author, :description, :title, :photo, :category_ids
scope :breaking, lambda { |category_ids|
joins(:categorizations).where('categorizations.category_id' => category_ids)
}
end
class Category < ActiveRecord::Base
attr_accessible :name
has_many :categorizations
has_many :posts, :through => :categorizations
end
class Categorization < ActiveRecord::Base
attr_accessible :category_id, :position, :post_id
belongs_to :post
belongs_to :category
end
我寫在後模型範圍稱爲打破,我不知道如何使它在視圖中。此外,控制器會是什麼樣子,並且是爲了檢索特定類別下的帖子而打破範圍?
請問控制器怎麼樣,並查看他們看起來像什麼,謝謝 – daniel 2013-02-09 03:12:02
不幸的是,我不能在這裏回答。你將不得不通過一個教程來做到這一點,或提出另一個問題。 – jvnill 2013-02-09 03:16:39