Rails 视图中的 fields_for

发布于 2024-12-21 04:19:17 字数 522 浏览 5 评论 0原文

当我尝试在下面的视图代码中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奈何桥上唱咆哮 2024-12-28 04:19:17

您是否没有在控制器中构建 showing 对象?

@company.build_showing

如果您已在 Company 模型上定义了 accepts_nested_attributes_for,那么您需要在控制器以及父对象中设置嵌套对象。

Are you not building a showing object in your controller?

@company.build_showing

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文