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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:04:47+00:00 2026-06-03T23:04:47+00:00

Hy, I have a problem in a nested form. Actually, I have two problems,

  • 0

Hy,

I have a problem in a nested form. Actually, I have two problems, but the second one is minor.
The basic structure is like this :

class Connectable
  has_one :web_account
  accepts_nested_attributes_for :web_account
end

class Person < Connectable
end

class WebAccount
   belongs_to :owner, class_name => `Connectable`
end

And now, I would like to create a nested form to create a Person and a WebAccount at the same time. I have the following code :

<%= form_for @person do |f| %> 
   ...
   <%= f.fields_for web_accounts do |child| %>
      ....
   <end>
<end>

The only important attribute for WebAccount is name and is a string.

Note also the plural used in defining the child_form. I don’t know why, but when I use a singular (which seems right to me), rails just prints out an empty form, while using a plural works just fine. I added some code in the controller to remplace the :web_accounts hash entry given by the form with :web_account.

More importantly, I get following error :

WebAccount(#97097470) expected, got ActiveSupport::HashWithIndifferentAccess(#83887850)

I also tried doing it in a console, defining following hash :

p = { :name => "ab", :lastname => "cd", :web_account => { :name => "ab.cd" }}

but with the same result.

Here is the code in my controller :

def create
  params[:person][:status] = Status.where(:name => params[:person][:status]).first

  # Transforms the web_accounts entry into web_account
  params[:person][:web_account] = params[:person][:web_accounts]
  params[:person].delete(:web_accounts)

  @person = Person.new(params[:person])

  .... (the rest is the standard response)

end

The error is given at line 58, which is the Person.new(…) line in the code above. I could print out the full framework trace if needed, but it is, as usual, rather long.

Why isn’t this working? I just can’t my head around it, as it seems to me that I have followed all the online tutorials… Could it the be the inheritance?

  • 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-03T23:04:48+00:00Added an answer on June 3, 2026 at 11:04 pm

    You should use web_account_attributes instead of web_account. Docs

    Try in the console:

    p = { :name => "ab", :lastname => "cd", :web_account_attributes => { :name => "ab.cd" }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem: After instantiating this Window, open all nested expanders on the
I have a nested form which looks something like: <FORM METHOD=GET NAME=mainForm ACTION=<%=response.encodeURL(updateForm.jsp)%>> </FORM>
I have this problem: My web application has a form where the users can
I have a nested form problem. I implemented the nested forms solution form the
i am making nested form, like it was done in railscasts and have a
I have a problem with nested templates and their template specialization. Given the following
Is it possible to tie nested generics/captures together? I often have the problem of
I'm having a problem with some for nested loops that I have to convert
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
the problem i have is that i have multiple nested master pages: level 1

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.