Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7523577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:50:36+00:00 2026-05-30T02:50:36+00:00

When my form gets posted, it will first create my model object#1, and if

  • 0

When my form gets posted, it will first create my model object#1, and if it succeeds, then it will create model object#2.

My form field needs to have a mix of both input fields for both model objects.

Can I do this using form helpers or should I just do this manually?

Update

Below are my models:

My models:

Account
  has_many :users
  has_one  :primary_user, :class_name => 'User'

User
  has_one :account

My user table has:

account_id

My account table:

primary_user_id

So during registration/signup for an account, I want to also include the fields from the user object:

user_name
email
password

So when the account is created, the primary_user user account is also created.

How can I do this?

PSS: Which side of the associate should be nullable, the account_id on the user table or the primary_user on the account side? Because currently I have no nulls on both sides and that won’t work!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:50:38+00:00Added an answer on May 30, 2026 at 2:50 am

    Model code

    class Account < ActiveRecord::Base
      has_many :users
      has_one  :primary_user, :class_name => "User", 
        :conditions => {:is_primary => true}
    
      accepts_nested_attributes_for :primary_user, :allow_destroy => true
    end
    

    Controller Code

    class AccountsController < ApplicationController
    
      def new
        @account = Account.new(:primary_user => User.new)
      end
    
      def create
        @account = Account.new(params[:account])
        if @account.save
          flash[:info] = "Created account"
          redirect_to root_url
        else
          render :new
        end
      end
    end
    

    View code

    - semantic_form_for @account do |f|
      - f.inputs do
        != f.input :company_name
        != f.input :address
        != f.input :city
        != f.input :state
        - f.semantic_fields_for :primary_user do |puf|
          != f.input :name
          != f.input :login
          != f.input :password
          != f.input :password_confirmation
      - f.buttons  do
        != f.commit_button 'Save'
        ! #{link_to 'Cancel', root_url}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a HTML/PHP5 page with a form, then when it gets posted, it
I have a form and when its posted, some of its data gets saved
Ok I am trying to get the users First Name the form gets their
I have a basic HTML form that gets inserted into a server side div
We have a web application that is based around a form that gets passed
I have a form that sometimes gets linked to with some query string parameters.
I have a Ruby DateTime which gets filled from a form. Additionally I have
I have a html page with a form. The form has Div which gets
When a form gets posted, I get some checkbox values like the below: Array
All, When a form gets posted, I get some checkbox values like the below:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.