0

I have article model with the following attributes: article.rb

  class Article < ActiveRecord::Base
    attr_accessible :content, :title, :tag_list, :type_list
 end

Now for creating each type of the article I want to have a different _form view with different fields.

Does it mean that I need to add new attributes to my article.rb or I have to add multiple models for my article controller for each type?

4

1 回答 1

0

考虑到上面的评论,我建议你选择单表继承。关于 STI 的一个很好的教程在这里http://juixe.com/techknow/index.php/2006/06/03/rails-single-table-inheritance/

这个解决方案的优点是你仍然可以做到Post.all。缺点是 db 表将有很多列,大多数记录未使用(每条记录将仅使用填充的类型特定值)

如果您有任何问题,请提出,我会尽力提供帮助:)

于 2013-07-02T13:47:44.023 回答