您好我有關聯一個小問題,我使用Rails 3.2的工作,我想創建一個特殊的博客,這個博客有許多部分,這部分有很多的文章和一篇文章屬於一個類別。所以,我的型號有:模特協會
class Article < ActiveRecord::Base
belongs_to :section
belongs_to :category
class Category < ActiveRecord::Base
has_many :articles
class Section < ActiveRecord::Base
has_many :article
belongs_to的部分,因此文章,在routes.rb中:
resources :sections do
resources :articles
end
耙路線:
POST /sections/:section_id/articles(.:format) articles#create
new_section_article GET /sections/:section_id/articles/new(.:format) articles#new
edit_section_article GET /sections/:section_id/articles/:id/edit(.:format) articles#edit
section_article GET /sections/:section_id/articles/:id(.:format) articles#show
PUT /sections/:section_id/articles/:id(.:format) articles#update
DELETE /sections/:section_id/articles/:id(.:format) articles#destroy
sections GET /sections(.:format) sections#index
POST /sections(.:format) sections#create
new_section GET /sections/new(.:format) sections#new
edit_section GET /sections/:id/edit(.:format) sections#edit
section GET /sections/:id(.:format) sections#show
PUT /sections/:id(.:format) sections#update
DELETE /sections/:id(.:format) sections#destroy
所以我的問題是如何創建一個Categories_controller索引並顯示操作。 表明,屬於這一類的文章,並有相應的文章路徑意見的link_to(類別#顯示)。
謝謝,我想我的邏輯是昨天失敗了,我一直在尋找無類路由訪問的文章。謝謝您的回答! – 2012-04-30 01:01:10