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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:52:50+00:00 2026-05-22T01:52:50+00:00

I have the following models defined in my application User Profile Address Here is

  • 0

I have the following models defined in my application

  • User
  • Profile
  • Address

Here is my user model:

class User < ActiveRecord::Base

  # 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, :password_confirmation, :remember_me, :profile_attributes

  has_one :profile
  accepts_nested_attributes_for :profile
end

Here is my profile model:

class Profile < ActiveRecord::Base

  attr_accessible :first_name, :last_name, :organization, :telephone_number, :user_id, :address_attributes

  belongs_to :user
  has_one :address

  accepts_nested_attributes_for :address
end

Here is my address model:

class Address < ActiveRecord::Base
  attr_accessible :street, :street_cont, :city, :state, :zip_code
  belongs_to :profile
end

I am using devise for authentication so in my view I have the following for registration:

<% resource.build_profile %>
<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <p><%= f.label :email %><br />
  <%= f.email_field :email %></p>

  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></p>

  <%=f.fields_for :profile do |profile_form| %>
      <p><%= profile_form.label :first_name %><br />
      <%= profile_form.text_field :first_name %></p>

      <p><%= profile_form.label :last_name %><br />
      <%= profile_form.text_field :last_name %></p>

      <p><%= profile_form.label :organization %><br />
      <%= profile_form.text_field :organization %></p>

      <p><%= profile_form.label :telephone_number %><br />
      <%= profile_form.text_field :telephone_number %></p>

      <%=f.fields_for :address do |address_form| %>
        <p><%= address_form.label :street %><br />
        <%= address_form.text_field :street %></p>

        <p><%= address_form.label :street_cont %><br />
        <%= address_form.text_field :street_cont %></p>

        <p><%= address_form.label :city %><br />
        <%= address_form.text_field :city %></p>

        <p><%= address_form.label :state %><br />
        <%= address_form.text_field :state %></p>

        <p><%= address_form.label :zip_code %><br />
        <%= address_form.text_field :zip_code %></p>
     <% end %>
  <% end %>

  <p><%= f.submit "Sign up" %></p>
<% end %>

<%= render :partial => "devise/shared/links" %>

The form renders correctly but when I view the source I see this for the address fields:

<input id="user_address_street" name="user[address][street]" size="30" type="text" />

for the profile section I see:

<input id="user_profile_attributes_first_name" name="user[profile_attributes][first_name]" size="30" type="text" />

When I save the form, the user and profile are saved to the database but not the address. I’m obviously doing something wrong possibly with my model relationships but I don’t know how to go about solving this.

Any help would be appreciated.

  • 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-22T01:52:51+00:00Added an answer on May 22, 2026 at 1:52 am

    Change this:

     <%=f.fields_for :address do |address_form| %>
    

    To this:

    <%=profile_form.fields_for :address do |address_form| %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
Say I have the following in my models.py : class Company(models.Model): name = ...
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
Let's say I have the following model: class Contest: title = models.CharField( max_length =
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
How can I achieve the following? I have two models (blogs and readers) and
If I have the following: {hdrs: [Make,Model,Year], data : [ {Make:Honda,Model:Accord,Year:2008} {Make:Toyota,Model:Corolla,Year:2008} {Make:Honda,Model:Pilot,Year:2008}] }
Suppose I have the following (rather common) model Client invokes web service request ->
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.