私は Rails を初めて使用し、ブログ サイトを作成しています。投稿にカテゴリが必要で、最終結果の URL は次のようになります - foo.com/category(title)/post(title) なのでたくさんのグーグルの後、このレールキャストhttp://railscasts.com/episodes/47-two-many-to-manyを見ました。次のモデルがありますが、ルートがどうあるべきかわかりません。
すべての投稿を表示するには、カテゴリのインデックス ビューを使用する必要がありますか?
モデル - 分類
class Categorisations < ActiveRecord::Base
attr_accessible :category_id, :product_id
end
モデル - カテゴリ
class Category < ActiveRecord::Base
attr_accessible :title, :image
has_many :categorisations
has_many :posts, :through => :categorisations
end
モデル - ポスト
class Post < ActiveRecord::Base
attr_accessible :body, :is_verified, :publish_date, :title, :url, :tag_list, :image, :category_id
has_many :categorisations
has_many :categories, :through => :categorisations
end