0

好吧,我是新来的,我有以下几点:

class Post < ActiveRecord::Base
   belongs_to :category
   ...
end

class Category < ActiveRecord::Base
   has_many :posts
   ...
end

我想创建一个帖子,并从下拉列表中选择其类别:

...
select("post", "category", Post::CATEGORIES, {:include_blank => true})
...

当我尝试保存时,它说类别属性不存在。

我该怎么做?

4

1 回答 1

2

post 表仅包含类别 ID,因此您需要分配给category_id

select("post", "category_id", Post::CATEGORIES, :include_blank => true)
于 2013-01-10T12:43:08.757 回答