I use formtastic and formtastic_cocoon to create a nested form.
Everything seems to work well, dynamically adding a nested form to an existing form, with one exception.
Users and users have entries.
When I create a user and add a record, I get
-User
- Entry (empty)
- Entry Test 1
I must have
-User
- Entry Test 1
I'm not sure why a blank entry always appears.
My models
class User <ActiveRecord :: Base
validates: name,: presence => true
has_attached_file: photo
has_many: tasks,: dependent =>: destroy
accepts_nested_attributes_for: tasks,: allow_destroy => true
end
class Task <ActiveRecord :: Base
attr_accessible: entry
belongs_to: user
end
my creation controller (I think this is the right controller)
def create
@user = User.new (params [: user])
if @ user.save
flash [: notice] = "Successfully created user."
redirect_to @user
else
render: action => 'new'
end
end
def create
@task = Task.new (params [: task])
if @ task.save
flash [: notice] = "Successfully created task."
redirect_to @task
else
render: action => 'new'
end
end
Empty entries are displayed in the database, so I don't think this is a problem with the html.erb files, but I can post them here if that helps.
source share