私は単純なブログ サイトを持っており、特定のカテゴリから投稿を取得しようとしています。以下のようにモデルを設定しました。
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
投稿モデルに break というスコープを書きましたが、それをビューでレンダリングする方法がわかりません。また、コントローラーはどのように見え、特定のカテゴリの投稿を取得するためにスコープが壊れていますか?