使用类表继承模型处理表单
我想使用 form_for
,除非我有使用 citier
gem 的类表继承模型。它们的定义如下:
class Fruit < ActiveRecord::Base
# calories:integer
# color:string
end
class Apple < Fruit
# is_sauce:boolean
end
class Banana < Fruit
# is_peeled:boolean
end
问题是我希望表单的第一部分填写我的 Fruit
模型的属性。然后,根据水果类型(Apple
、Banana
)的选择字段,我想填写该特定模型的属性,但我仍然希望使用 <代码>form_for 帮助器。关于如何处理这个问题有什么建议...或额外的说明吗?谢谢。
I would like to use form_for
except I have class table inheritance models using the citier
gem. They are defined as such:
class Fruit < ActiveRecord::Base
# calories:integer
# color:string
end
class Apple < Fruit
# is_sauce:boolean
end
class Banana < Fruit
# is_peeled:boolean
end
The problem is that I want the first part of my form to fill out attributes for my Fruit
model. Then depending on a select field on what type of fruit (Apple
, Banana
), I then want to fill out attributes for that particular model yet I still want validations with the form_for
helper. Any suggestions on how I can approach this... or additional clarification? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终做的是在创建表单之前询问模型。然后使用许多部分。
What I ended up doing was asking for the model before creating the form. Then using many partials.