Rails视图中的fields_for [英] fields_for in rails view
本文介绍了Rails视图中的fields_for的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试在下面的视图代码中使用fields_for时,company_name未显示在视图中.我在做什么错了?
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
推荐答案
您是否未在控制器中构建showing
对象?
Are you not building a showing
object in your controller?
@company.build_showing
如果在Company
模型上定义了accepts_nested_attributes_for
,则需要在控制器以及父对象中设置嵌套对象.
If you've defined accepts_nested_attributes_for
on your Company
model, then you'll need to set up the nested objects in the controller as well as the parent objects.
这篇关于Rails视图中的fields_for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文