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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:50:15+00:00 2026-06-18T02:50:15+00:00

I have the following two model classes I’d like to create with a single

  • 0

I have the following two model classes I’d like to create with a single Active Admin form:

class User < ActiveRecord::Base
    has_one :profile
    attr_accessible :email, :profile, :profile_attributes
    accepts_nested_attributes_for :profile
end

class Profile < ActiveRecord::Base
    belongs_to :user
    attr_accessible :name, :user_id
end

Here’s how I nest the two models in a single “Create User” form using Active Admin:

form do |f|
      f.inputs "User Fundamentals" do
        f.input :email
      end

      #f.inputs "User Profile", :for => :profile do |profile_form|
      f.inputs :name => "User Profile", :for => [f.object.profile || Profile.new] do |profile_form|
        profile_form.input :name
      end
      f.buttons
end

The form is being displayed perfectly fine. But after clicking “Create” I get the following error:

ActiveRecord::AssociationTypeMismatch in Admin::UsersController#create

Profile(#70204018617440) expected, got ActiveSupport::HashWithIndifferentAccess(#70204014589500)

This is how the request parameter looks like:

{"utf8"=>"✓",
 "authenticity_token"=>"...",
 "user"=>{"email"=>"user@test.com",
 "profile"=>{"name"=>"my name"}},
 "commit"=>"Create User"}

Here’s the trace:

activerecord (3.2.9) lib/active_record/associations/association.rb:204:in `raise_on_type_mismatch'
activerecord (3.2.9) lib/active_record/associations/has_one_association.rb:8:in `replace'
activerecord (3.2.9) lib/active_record/associations/singular_association.rb:17:in `writer'
activerecord (3.2.9) lib/active_record/associations/builder/association.rb:51:in `block in define_writers'
activerecord (3.2.9) lib/active_record/attribute_assignment.rb:94:in `block in assign_attributes'
activerecord (3.2.9) lib/active_record/attribute_assignment.rb:93:in `each'
activerecord (3.2.9) lib/active_record/attribute_assignment.rb:93:in `assign_attributes'
activerecord (3.2.9) lib/active_record/base.rb:497:in `initialize'
inherited_resources (1.3.1) lib/inherited_resources/base_helpers.rb:52:in `new'
inherited_resources (1.3.1) lib/inherited_resources/base_helpers.rb:52:in `build_resource'
activeadmin (0.5.1) lib/active_admin/resource_controller/callbacks.rb:15:in `build_resource'
inherited_resources (1.3.1) lib/inherited_resources/actions.rb:31:in `create'
activeadmin (0.5.1) lib/active_admin/resource_controller/actions.rb:48:in `create'
actionpack (3.2.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.9) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.9) lib/active_support/callbacks.rb:447:in `_run__1741973691692741514__process_action__12141427009768339__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.9) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.9) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.9) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:601:in `call'
omniauth (1.1.1) lib/omniauth/strategy.rb:177:in `call!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157:in `call'
sass (3.2.3) lib/sass/plugin/rack.rb:54:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.9) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__1872540156051940127__call__3542490292744583204__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.9) lib/rails/engine.rb:479:in `call'
railties (3.2.9) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'

I tried to figure this one out for quite a while (added accepts_nested_attributes_for, etc.) but can’t seem to find out what might cause this. Therefore any help would be greatly appreciated! Thanks!

Update:
my routes:

batch_action_admin_users POST   /admin/users/batch_action(.:format)              admin/users#batch_action
                          admin_users GET    /admin/users(.:format)                           admin/users#index
                                      POST   /admin/users(.:format)                           admin/users#create
                       new_admin_user GET    /admin/users/new(.:format)                       admin/users#new
                      edit_admin_user GET    /admin/users/:id/edit(.:format)                  admin/users#edit
                           admin_user GET    /admin/users/:id(.:format)                       admin/users#show
                                      PUT    /admin/users/:id(.:format)                       admin/users#update
                                      DELETE /admin/users/:id(.:format)                       admin/users#destroy

Update 2: Here’s my routes.rb file:

MyApp::Application.routes.draw do
    resources :users
    resources :profiles
end
  • 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-18T02:50:16+00:00Added an answer on June 18, 2026 at 2:50 am

    Finally managed to solve this annoying problem. Here’s how I did it.

    In migration I changed the t.integer for user_id to t.references user:

    class CreateProfiles < ActiveRecord::Migration
      def change
         create_table :profiles do |t|
            t.references :user
            t.string :name
            t.timestamps
         end
      end
    end
    

    On top of that I added the follow lines to my users & profiles model:

    class User < ActiveRecord::Base
      has_one :profile
      accepts_nested_attributes_for :profile
      attr_accessible :email, :profile
      alias_method :subtest=, :subtest_attributes= # <-- THIS is the new addition
    end
    

    Now it’s working like a charm 🙂

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

Sidebar

Related Questions

Let's say I have the following two classes: package example.model; public class Model {
How do I model the following using Castle ActiveRecord? I have two classes, Customer
I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
I have two Django model classes that are structured similar to the following: class
I have the following two classes: class Menu < ActiveRecord::Base has_many :menu_headers accepts_nested_attributes_for :menu_headers
The scenario Suppose I have the following two model classes: public class ProductColor {
I have the following two models: class Parent < ActiveRecord::Base has_one :child, dependent: :destroy
I have two model classes: Cars and Customers , Model Cars : class car
I have the following two models class ModelOne(models.Model): mod_desc = models.CharField(max_length=25) is_active = models.BooleanField(default=True)
Say I have two classes: class A(db.Model): class B(db.Model): a_reference = ReferenceProperty(A) I can

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.