我現在有這幾個 model:
Category
,PostCategory
,Post
.
class Category < ActiveRecord::Base
attr_accessible :name, :type
end
class PostCategory < Category
has_many :posts, :dependent => :destroy
end
class Post < ActiveRecord::Base
belongs_to :postcategory #還是:post_category?
attr_accessible :title, :content, :post_category_id #之前我命名是category_id
end
然後 controller 裡面無法獲取到@post_category
class PostsController < ApplicationController
def index
@post_category = PostCategory.find(params[:id])
@posts = @post_category.posts
end
end
現在訪問報錯:
*ActiveRecord::RecordNotFound in PostsController#index **
Couldn't find PostCategory without an ID