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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:58:56+00:00 2026-05-30T00:58:56+00:00

anyone passed through this? the scene is a nested form on user creation, where:

  • 0

anyone passed through this?

the scene is a nested form on user creation, where:

  1. User has_one Profile
  2. Profile belongs_to user

so my factory is configured in this way but when i run the test aways bring me this result:

 Failure/Error: user_attributes[:user_attributes][:profile_attributes] = Factory.attributes_for :profile
     NoMethodError:
       undefined method `[]=' for nil:NilClass

Factory

Factory.define :user do |f|
  f.after_build do |user|  
    f.email                 'exemple@exemple.com'
    f.password              'password'
    f.password_confirmation 'password'  
    user.profile ||= Factory.build(:profile, :user => user)
  end
end

Factory.define :profile do |f| 
  f.after_build do |profile|
    profile.user ||= Factory.build(:user, :profile => profile)

  f.nome          'alguem'
  f.sobrenome     'alguem'
  f.endereco      'rua x'
  f.numero        '95'
  f.genero        'm'
  f.complemento   'casa'
  f.bairro        'bairro x'
  f.cidade        'cidade x'
  f.estado        'estado x'
  f.cep           '232323'


end

end

Users_spec

describe "CreateUsers" do

    before :each do

      user_attributes = Factory.attributes_for :user
      user_attributes[:user_attributes][:profile_attributes] = Factory.attributes_for :profile

    @user = User.new(user_attributes)

    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-05-30T00:58:58+00:00Added an answer on May 30, 2026 at 12:58 am

    Assuming that you are trying to auto create a profile when you create a user then try building it this way, using the new FactoryGirl syntax:

    Factory file:

    FactoryGirl.define do
      factory :user do
        email                 'exemple@exemple.com'
        password              'password'
        password_confirmation 'password'
        after_build do |profile|
          user.profile << FactoryGirl.build(:profile, :user => user)
        end
      end
    
      factory :profile do
        nome          'alguem'
        sobrenome     'alguem'
        endereco      'rua x'
        numero        '95'
        genero        'm'
        complemento   'casa'
        bairro        'bairro x'
        cidade        'cidade x'
        estado        'estado x'
        cep           '232323'
        user
      end
    end
    

    Note the addition of user in the profile factory with defines the association on the profile record. Provided your user factory is called :user you do not have to pass any arguments.

    You should then be able to call

    @user = FactoryGirl.build(:user)
    

    and it will build both a user and a profile. You can see the profile by calling @user.profile.

    If you call @user = FactoryGirl.create(:user) it will create both the user and the profile, inserting the user_id into the profile record.

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

Sidebar

Related Questions

I wonder if anyone could suggest the best way of looping through all the
Anyone know of a library that handles parsing arguements passed from the command line
Anyone know of a way to capture keyboard events (keyup / keydown) in Portable
Anyone know how to do this without using a third party program? If there
Basically I've passed a script in the terminal through /bin/bash [path] or /bin/sh [path],
I have an object handed into our library and passed through various processes. I
I previously asked this question here: Stop user from using enter to pass a
When using a form like this: <h2> <%:Model.EulaTitle %> </h2> <p> <%=Model.EulaHtml %> </p>
I'm looking for the easiest and most sensible way to allow this scenario to
If there's anyone who can help me understand this one, I will be impressed.

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.