[英]embedded polymorphic association model form
I have these models: 我有以下模型:
model 1: 模型1:
module Ems
class Article < ActiveRecord::Base
has_many :images, :as => :imageable
accepts_nested_attributes_for :images
end
end
model 2: 模型2:
module Ems
class Image < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
end
view: 视图:
= form_for @article do |f|
%div
= f.label :title
= f.text_field :title
%div
- f.fields_for :images do |builder|
= builder.label :title
= builder.text_field :title
I don't get any errors however I also dont get the form fields for the embedded image form. 我没有任何错误,但是我也没有得到嵌入式图像表单的表单字段。 All I get is an empty DIV.
我得到的只是一个空的DIV。
Can anyone point me in the right direction? 谁能指出我正确的方向?
Thanks 谢谢
try after replacing - with = at where you are calling fields_for 在调用fields_for的地方用=替换后尝试
= f.fields_for :images do |builder|
The fields_for returns form HTML, so you need to render it on UI. fields_for返回HTML格式,因此您需要在UI上呈现它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.