Create nested form from different controller

Models:

  • User
  • Application

Relationship:

User has many Application

Normally, I’d use fields_for in User form to add/edit/destroy Application associated to the User. But since the User itself has a lot of fields, I’d like to separate User and Application form. I’m thinking something like this:

GET /user/:user_id/applications will render the form (probably using cocoon gem). It will submit the form to POST /user/:user_id/applications.

Is this OK? Or maybe there’re better ways to do this?

Summary:

  • GET /user/:user_id/applications - renders the form for edit/update/destroy Application for the selected User
  • POST /user/:user_id/applications - process the form
  • GET /user/:user_id - will show the User and Application data.
  • There will be no new, edit, update, destroy actions for Application.

First, for the relationship I would do this:

(user.rb file): has_many :applications

(application.rb file): has_and_belongs_to_many :users

I am not sure I understand what the rest of your question is.

1 Like