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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:12:22+00:00 2026-05-13T19:12:22+00:00

I have a user and a profile model. One user can have many profiles.

  • 0

I have a user and a profile model. One user can have many profiles. I need to access only one information from the profiles section (viz the phone number) in my user model during the user creation process. Hence I’m trying to get it done through attr_accessible. My user.rb looks like this.

has_many :profiles
attr_accessible :handle, :email, :password, :profile_mobile_number
attr_accessor : :profile_mobile_number

The problem that I’m facing is that when I try to call the getter method profile_mobile_number in a method in user.rb (the method is private, though I think it doesn’t matter), I’m getting a null value. I use the following in my users/new.html.erb form

My question is what is the right way to do this? Should I use <% f.fields_for :profile do |ff| -%> or <% f.fields_for :profiles do |ff| -%> (notice that the second one is plural). When I use the plural :profiles, I don’t even see the fields on the form. What am I missing here? And what is the tense that needs to be used in model user.rb? :profile_phone_number or :profiles_phone_number? Thanks.

  • 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-13T19:12:22+00:00Added an answer on May 13, 2026 at 7:12 pm

    You could do something like the following:

    <% form_for @user, :url => { :action => "update" } do |user_form| %>
      ...
      <% user_form.fields_for :profiles do |profiles_fields| %>
         Phone Number: <%= profiles_fields.text_field :profile_mobile_number %>
       <% end %>
    <% end %>
    

    But since you already have an association, then might as well use ‘accepts_nested_attributes_for‘

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

Sidebar

Related Questions

In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User
I have a user profile page on my web app which has contact information.
I have two tables for storing information about a user. One is for authentication,
I have a user model and a profile model. user has_one :profile profile belongs_to
In my app I have three tables: Users Profiles Friends The User has one
I have a profile model I use to supplement the built in User model.
I have a user model which has_one profile. The user model has a name
I have a user model that has_one profile, and the profile belongs to the
The design I have a User model that belongs to a profile through a
I have a profile. class UserProfile(models.Model): user = models.ForeignKey(User, related_name=%(class)s, unique=True) providers = models.ManyToManyField(ServiceProvider,

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.