【问题标题】:fields_for in rails view在rails视图中的fields_for
【发布时间】:2011-12-12 00:07:09
【问题描述】:

当我尝试在下面的视图代码中使用 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

【问题讨论】:

    标签: ruby-on-rails-3 view fields-for


    【解决方案1】:

    您不是在控制器中构建showing 对象吗?

    @company.build_showing
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      相关资源
      最近更新 更多