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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:03:53+00:00 2026-06-02T08:03:53+00:00

In my current rails app, I have a User model which has_one :user_detail. Currently,

  • 0

In my current rails app, I have a User model which has_one :user_detail. Currently, I cannot get the form to display the fields for the nested attribute unless I already have it seeded with the seeds.rb file.

Here is my User model

class User < ActiveRecord::Base
  has_one :user_detail, :dependent => :destroy
  accepts_nested_attributes_for :user_detail
  attr_accessible :email, :password, :password_confirmation, :access_level, :first_name, :last_name, :user_detail_attributes
  has_secure_password
end

and my UserDetail model

class UserDetail < ActiveRecord::Base
  belongs_to :user
end

and my form

<%= form_for [:admin, @user] do |f| %>
  <p><%= f.text_field(:name, :placeholder => 'Name')%></p>
  <p><%= f.label(:email) %></p>
  <p><%= f.email_field(:email, :placeholder => 'Your Email')%></p>
  <p><%= f.password_field(:password, :placeholder => 'Choose a password') %></p>
  <p><%= f.password_field(:password_confirmation, :placeholder => 'Confirm Password') %></p>

    <%= f.fields_for :user_detail do |u| %>
      <p><%= u.text_field(:country, :placeholder => 'Country') %></p>
      <p><%= u.text_field(:state, :placeholder => 'State') %></p>
      <p><%= u.text_field(:city, :placeholder => 'City') %></p>
      <p><%= u.text_field(:phone, :placeholder => 'Phone') %> </p>
    <% end %>

  <p><%= submit_tag("Add Owner") %></p>

The fields won’t show up, until I seed them with this
seeds.rb

UserDetail.delete_all
owner1detail = UserDetail.create(:zip => "84770",
                              :country => "US",
                              :state => "Ut",
                              :city => "St. George",
                              :user_id => owner1.id
                             )

and I run rake db:seed. Once I do this and I edit an existing user, the fields show up, all filled in. However, when creating a user they don’t show up. Any ideas why?

  • 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-02T08:03:54+00:00Added an answer on June 2, 2026 at 8:03 am

    I moved the build to my controller like so and it worked

    def new
      @user = User.new
      @user.build_user_detail
    end  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails 2.3.x app that implements the act_as_authentic in User model and
I have a rails app that is using Devise, with a User model, no
I have a rails app with devise for my user model. In my app
I'm current designing a Rails application that uses a form for user login, then
My Rails application have a User model and a Group model, where User belongs
In my Rails 3.0.5 app I have columns on my Profile model for privacy.
I have a House model in my rails app that has_many deals. I am
I am trying to create form that contains another model in rails. I have
I have a partial in my rails app that loads the vote form (It's
Is there some way to replicate rails' link-to-unless-current? Ie. if i have a list

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.