views:

120

answers:

1

Any way to access a nested form_bulder.object?

## controller
@project = Project.new
@project.tasks.build

form_for(@project) do |f|
  f.object.nil? ## returns false

  fields_for :tasks do |builder|
    builder.object.nil? ## returns true
  end
end
+2  A: 

You must have accepts_nested_attributes_for in the Project model in order for the object to be passed.

class Project < ActiveRecord::Base
  has_many :tasks
  accepts_nested_attributes_for :tasks ## this is required
end
chap