Rails 视图中的 fields_for
当我尝试在下面的视图代码中使用 fields_for 时,company_name 没有显示在视图中。我做错了什么?
= form_for @company do |f|
-if @company.errors.any?
#error_explanation
%h2= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:"
%ul
- @company.errors.full_messages.each do |msg|
%li= msg
=f.fields_for :showing do |t|
.field
= t.label :company_name
= t.text_field :company_name
.field
= f.label :geography
= f.text_area :geography
When I attempt to use fields_for in the view code below, the company_name is not showing up in the view. What am I doing wrong?
= form_for @company do |f|
-if @company.errors.any?
#error_explanation
%h2= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:"
%ul
- @company.errors.full_messages.each do |msg|
%li= msg
=f.fields_for :showing do |t|
.field
= t.label :company_name
= t.text_field :company_name
.field
= f.label :geography
= f.text_area :geography
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否没有在控制器中构建
showing
对象?如果您已在
Company
模型上定义了accepts_nested_attributes_for
,那么您需要在控制器以及父对象中设置嵌套对象。Are you not building a
showing
object in your controller?If you've defined
accepts_nested_attributes_for
on yourCompany
model, then you'll need to set up the nested objects in the controller as well as the parent objects.