【发布时间】:2014-04-07 02:17:50
【问题描述】:
我的应用中有以下模型
class User < ActiveRecord::Base
has_many :articles
has_many :tour_companies
has_many :accomodations
end
class Articles < ActiveRecord::Base
belongs_to :user
belongs_to :bloggable, :polymorphic => true
end
class TourCompany < ActiveRecord::Base
belongs_to :user
has_many :articles, :as => :bloggable
end
class Accommodation < ActiveRecord::Base
belongs_to :user
has_many :articles, :as => :bloggable
end
现在我的问题是我希望登录用户能够写一篇文章并使用表单 collection_select 来选择文章应该与他/她的哪个旅游公司或住宿相关联,我该怎么做轨道4?如何从表单集合选择中选择可博客类型和 ID?我不想要嵌套资源
【问题讨论】:
标签: ruby-on-rails-4 polymorphic-associations