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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:10:29+00:00 2026-05-31T16:10:29+00:00

I have a User and Account models with has_one association and nested attributes. My

  • 0

I have a User and Account models with has_one association and nested attributes.
My problem is that when signing up user via Devise, Account is not created and no error is generated in the log.
I am using Rails 3.2 with Devise 2.0.4.

user.rb

class User
  include Mongoid::Document

  has_one :account, :inverse_of => :user

  accepts_nested_attributes_for :account

  field :name
  validates_presence_of :name
  validates_uniqueness_of :name, :email, :case_sensitive => false
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :account_attributes

  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
  ...
end

account.rb

class Account
  include Mongoid::Document

  belongs_to :user, :inverse_of => :account

  field :name

  validates_presence_of :user
  attr_accessible :name, :user_id

end

registration_controller.rb

class RegistrationsController < Devise::RegistrationsController
  def new
    resource = build_resource({})
    resource.build_account
    respond_with resource
  end
end 

view

<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <%= f.fields_for :account do |account_form| %>
    <div><%= account_form.label 'Company' %>
    <%= account_form.text_field :name %></div>
  <% end %>
...

here is my console output

Started POST "/users" for 127.0.0.1 at 2012-03-21 03:40:55 -0700
Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓",         "authenticity_token"=>"dAmJrthe/IjlHzjBI2kF9nkTxwIWM0o69Q1PI2nd95o=", "user"=>{"account_attributes"=>{"name"=>"comp11"}, "name"=>"user11", "email"=>"uu3@u3.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
MONGODB (1ms) myapp_development['$cmd'].find({"count"=>"users", "query"=>{:email=>"uu3@u3.com"}, "fields"=>nil}).limit(-1)
MONGODB (0ms) myapp_development['$cmd'].find({"count"=>"users", "query"=>{:name=>/^user11$/i}, "fields"=>nil}).limit(-1)
MONGODB (0ms) myapp_development['$cmd'].find({"count"=>"users", "query"=>{:email=>/^uu3@u3\.com$/i}, "fields"=>nil}).limit(-1)
MONGODB (1ms) myapp_development['users'].insert([{"email"=>"uu3@u3.com", "encrypted_password"=>"$2a$10$lY6aHKTyeVALAcIkX.Ipke5YMj7/viU9Hy5s.jsQAq7cfCBtJtXaO", "sign_in_count"=>0, "_id"=>BSON::ObjectId('4f69b0377e3d3639bf000008'), "name"=>"user11"}])
MONGODB (0ms) myapp_development['users'].update({"_id"=>BSON::ObjectId('4f69b0377e3d3639bf000008')}, {"$set"=>{"last_sign_in_at"=>2012-03-21 10:40:56 UTC, "current_sign_in_at"=>2012-03-21 10:40:56 UTC, "last_sign_in_ip"=>"127.0.0.1", "current_sign_in_ip"=>"127.0.0.1", "sign_in_count"=>1}})
Redirected to http://localhost:3000/
Completed 302 Found in 257ms

As you can see, I do not see anything about creating Account. Also verified that no Account collection is created by viewing the MongoDB. What am I missing?
Thanks you for your help in advance.

  • 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-31T16:10:30+00:00Added an answer on May 31, 2026 at 4:10 pm

    Solved the problem.
    I needed to turn on :autosave

    has_one :account, :inverse_of => :user, :autosave => true
    

    mongoid docs pointed at the problem.

    Note that the :autosave option needs to be enabled for relational associations that accepts_nested_attributes_for is used for if you don’t want to manually save the relation on update.

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

Sidebar

Related Questions

I have an Account model that has_one User model, and a User model that
I have an Account model with the following : has_one :primary_user, :class_name => User,
I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
I have a user Sql Authentication account that has remote access to my database
I have a program that creates a Windows user account using the NetUserAdd() API
I believe that I have successfully impersonated my own user account while running an
I have a basic problem with a has_one and belongs_to association. I have two
I am not sure am I doing these correct. I have 3 models, Account,
Say that I have two models- Users and Accounts. Each account can have at
In 'ROOT_RAILS/models/users/account.rb' I have has_one :profile, :primary_key => app_profile_id, :foreign_key => id, :dependent =>

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.