我有以下型号:
class Topic < ActiveRecord::Base
has_many :posts, :dependent => :destroy
attr_accessible :name, :post_id
end
class Post < ActiveRecord::Base
belongs_to :topic, :touch => true
has_many :comments, :dependent => destroy
accepts_nested_attributes_for :topic, :comments
attr_accessible :name, :title, :content, :topic, :topic_attributes
end
class Comment < ActiveRecord::Base
belongs_to :Post
end
这个简单的表格有效吗?我可以同时访问2个嵌套模型吗?
simple_form_for @post do |f|
f.simple_fields_for :topic do |topic_form|
topic_form.input :name
end
f.simple_fields_for :comment do |comment_form|
comment_form.input :text
end
end
由于
答案 0 :(得分:0)