rails嵌套形式混乱

时间:2011-12-01 16:46:13

标签: ruby-on-rails partial-views

我有这个型号:

class Employment < ActiveRecord::Base
  accepts_nested_attributes_for :month_lines
end

并形成:

employment.new

= form_for @employment do |f|
      = f.fields_for :month_lines do |builder|
        = render "/month_lines/fields", :f => builder

month_lines / _fields

= f.number_field :days

我想在部分

中显示month_line.year

如何从_fields partial?

中访问month_line对象

1 个答案:

答案 0 :(得分:3)

这是非常简单的方法,但由于一些奇怪的原因,鲜为人知:

= f.object.year