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 8328779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:33:19+00:00 2026-06-09T01:33:19+00:00

The Signup form in my app allows users to create an account – it

  • 0

The Signup form in my app allows users to create an account – it also creates their user record and an accounts_users (has_many :through) record. Once they click submit, I am calling the ‘setup_account’ method to input several default values for the user’s new account. With that said, the method is close to working but is inputting incorrect values for the three records where I manually assign values (i.e. :user_id => @user or :account_id => @account). The incorrect value for account_id and user_id always end up being 1. Does anyone have any insight into why this is not working?

Here is my Account model:

  def self.setup_account(p)
    Account.transaction do
      @account = Account.new(p)
      @account.save!
      @user = @account.users.first
      @user.create_profile!
      @group = @account.groups.create!( :user_id => @user.id, :name => 'Default' )
      @group.members.create!( :account_id => @account.id, :user_id => @user.id )
      Role.all.each do |role|
        @account.roles_users.create!( :user_id => @user.id, :role_id => role.id )
      end
    end
    return @account
  end

Here is my AccountsController:

  def new
    @account = Account.new
    @user = @account.users.build()
    @account.accounts_users.build()
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @account }
    end
  end

  def create
    @account = Account.setup_account(params[:account])
    respond_to do |format|
      if !@account.nil?
        flash[:domain] = @account.subdomain
        format.html { redirect_to thanks_url }
        format.json { render json: @account, status: :created, location: @account }
      else
        format.html { render action: "new" }
        format.json { render json: @account.errors, status: :unprocessable_entity }
      end
    end
  end

My model associations are:

  • Account (has_many :users; :through account_users; has_many :accounts_users; has_many :groups; has_many :members; has_many :roles_users)
  • User (has_one :profile; has_many :accounts_users; has_many :accounts, :through => :accounts_users; has_many :members; has_many :groups; has_many :roles_users; has_many :roles, :through => :roles_users)
  • Accounts_User (belongs_to :account; belongs_to :user)
  • Group (has_many :members, as: membership; belongs_to :user; belongs_to :account)
  • Member (belongs_to :membership, :polymorphic => true; belongs_to :account; belongs_to :user)
  • Profile (belongs_to :user)
  • Role (has_many :roles_users; has_many :users :through => :roles_users; has_many :accounts, :through => :roles_users)
  • RolesUser (belongs_to :user; belongs_to :account; belongs_to :role)

Edit: Edited the setup_account method and create action.

  • 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-06-09T01:33:20+00:00Added an answer on June 9, 2026 at 1:33 am

    Check my comments in your model method,

    def self.setup_account(p)
      Account.transaction do
        @account = Account.new(p)
        # Account is not created yet so @account.users won't be retrieved properly, I guess
        # You need to save account first.
        @user = @account.users.first
        @user.build_profile
        @group = @account.groups.build( :user_id => @user, :name => 'Default' ) #Error
        @group.members.build( :account_id => @account, :user_id => @user ) #Error
        Role.all.each do |role| #Error
          @account.roles_users.build( :user_id => @user, :role_id => role.id )
        end
        # Try moving this above my comment.
        @account.save!
      end
    end
    

    Since you are using a transaction block, you can start saving things as soon as you build them. In case of any error, it’ll be rolled back automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to create a signup form for my django app. for this
I have a signup form where users kan enter their subdomain of choice when
I'm trying to create a form where a user can type in their email
I have a node.js app that loads a signup form when visiting localhost/user/signup: html
I've created my own signup form and creating the user using the Membership class.
I'd like to allow users the option to register using their Twitter account. Basically,
I am using Rails 3 and Devise to create an app where users arrive
I am running an app where a rails 3 app where a user creates
I am making a user signup app for an ecomerce site, but I have
I'm trying to user jQuery Validation plugin to validate a signup form, but I

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.