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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:15:56+00:00 2026-05-31T18:15:56+00:00

I am trying to expand the devise registration form to allow a new user

  • 0

I am trying to expand the devise registration form to allow a new user to create an organization (company) at the same time they sign up. I finally got the nested form fields visible (after reading several SO threads), but I have encountered an error that I believe to be associated with mass assignment.

I am a complete rails noob, still getting my feet wet. Other SO questions have gotten me this far, but now I am just stuck.

Here are my current files:

User Model:

class User < ActiveRecord::Base

  belongs_to :organization
  accepts_nested_attributes_for :organization

  validates_presence_of :first_name, :last_name
  validates_length_of :first_name, :maximum => 50
  validates_length_of :last_name, :maximum => 50

  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :first_name, :last_name, :password_confirmation, :remember_me, :organization_attributes, :organization

end 

Organization Model

class Organization < ActiveRecord::Base

  has_many :users, :foreign_key => "user_id"
  accepts_nested_attributes_for :users

end

Registration Form

<h2>Register for a new account</h2>

<% resource.build_organization %>

<%= form_for(resource, :html => { :class => 'form-horizontal' }, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>
  <fieldset>
    <legend class="hidden">Sign Up Form</legend>
    <h3>User Information</h3>
    <div class="control-group">
      <%= f.label :first_name, :class => 'control-label' %>  
      <div class="controls">
      <%= f.text_field :first_name %>  
      </div>
    </div>
    <div class="control-group">
      <%= f.label :last_name, :class => 'control-label' %>  
      <div class="controls">
      <%= f.text_field :last_name %>  
      </div>
    </div>

    <div class="control-group">
      <%= f.label :email, :class => 'control-label' %>  
      <div class="controls">
        <%= f.email_field :email %>
      </div>
    </div>

    <div class="control-group">
      <%= f.label :password, :class => 'control-label' %>
       <div class="controls">
         <%= f.password_field :password %>
      </div>
    </div>
    <div class="control-group">
      <%= f.label :password_confirmation, :class => 'control-label' %>
      <div class="controls">
        <%= f.password_field :password_confirmation %>
      </div>
    </div>    

    <h3>Company/Organization Information</h3>
    <%= f.fields_for resource.organization do |fo| %>
      <div class="control-group">
         <%= fo.label :name, :class => 'control-label' %>
         <div class="controls">
           <%= fo.text_field :name, :class => 'text_field' %>
         </div>
       </div>       
       <div class="control-group">
          <%= fo.label :subdomain, :class => 'control-label' %>
          <div class="controls">
            <%= fo.text_field :subdomain, :class => 'text_field' %>
          </div>
        </div>
       <div class="control-group">
         <%= fo.label :plan, :class => 'control-label' %>
         <div class="controls">
           <%= fo.text_field :plan, :class => 'text_field' %>
         </div>
       </div>
    <% end %>    

    <div class="form-actions">
      <%= f.submit "Sign up", :class => 'btn btn-primary' %>
      <%= link_to 'Forgot Password?', :new_user_password, :class => 'btn btn-info' %>
    </div>
  </fieldset>

<% end %>

Error Message

ActiveRecord::AssociationTypeMismatch in Devise::RegistrationsController#create

Organization(#70312257412900) expected, got ActiveSupport::HashWithIndifferentAccess(#70312251932740)
Rails.root: /Volumes/www/projects/ror/testapp

Application Trace | Framework Trace | Full Trace
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"SG/jlH2L3ATSqi1lBxlgbvWzx/sHVFlneX8vF/LKKZg=",
 "user"=>{"first_name"=>"",
 "last_name"=>"",
 "email"=>"",
 "password"=>"[FILTERED]",
 "password_confirmation"=>"[FILTERED]",
 "organization"=>{"name"=>"",
 "subdomain"=>"",
 "plan"=>""}},
 "commit"=>"Sign up"}

I am sure I am missing something simple. Looking forward to seeing what it is 😉

  • 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-31T18:15:58+00:00Added an answer on May 31, 2026 at 6:15 pm

    try this:

     
           f.fields_for :organization_attributes, resource.organization do |fo|
         

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

Sidebar

Related Questions

I'm currently trying to expand my PHP driven intranet site for my company. It
I'm trying to collapse or expand table rows with + and - sign displayed
I'm trying to expand my Core Data. So I added a new attribute to
I'm trying to create fancy looking Listbox . ListBoxItem s are supposed to expand
I am trying to expand my class with a new function, i can already
I'm trying to expand navigation options of the context menu on certain elements (specifically,
I'm trying to expand my sons interest from Warcraft 3 programming into C++ to
I have a table column I’m trying to expand and hide. jQuery seems to
After few weeks break, I'm trying to expand and extend my knowlege of templates
I am trying to make my DIV's height expand to it's child elements. 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.