0

Conceptually, is it possible to have a form in Rails that accepts input for both User and Profile fields? If so, how could I execute that? Do I need to set the form_for for both User and Profile?

The goal is to have two forms (one on the homepage and one at signup) that could potentially mix user/profile information when saved. FYI - here is how I add a user:

user = User.new
user.email = ""
user.password = ""
user.profile = Profile.new
user.profile.save
user.save
tvalent2
  • 4,959
  • 10
  • 45
  • 87

2 Answers2

1

Yes, you should look into accepts_nested_attributes_for, addressed in the Rails docs here.

For more information, please look into:

Community
  • 1
  • 1
hayesgm
  • 8,678
  • 1
  • 38
  • 40
1

You can use nested form, and a model with nested attributes to accomplish this. Follow the Ryan Bates tutorial on Nested Forms

rookieRailer
  • 2,313
  • 2
  • 28
  • 48