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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:12:49+00:00 2026-05-15T07:12:49+00:00

Two models (Rails 2.3.8): User; username & disabled properties; User has_one :profile Profile; full_name

  • 0

Two models (Rails 2.3.8):

User; username & disabled properties; User has_one :profile
Profile; full_name & hidden properties

I am trying to create a named_scope that eliminate the disabled=1 and hidden=1 User-Profiles. Moreover, while the User model is usually used in conjunction with the Profile model, I would like the flexibility to be able specify this using the :include => :profile syntax.

I have the following User named_scope:

  named_scope :visible, {
    :joins => "INNER JOIN profiles ON users.id=profiles.user_id",
    :conditions => ["users.disabled = ? AND profiles.hidden = ?", false, false]
  }

This works as expected when just reference the User model:

>> User.visible.map(&:username).flatten
=> ["user a", "user b", "user c", "user d"]

However, when I attempt to include the Profile model:

User.visible(:include=> :profiles).profile.map(&:full_name).flatten

I get an error that reads:

NoMethodError: undefined method `profile' for #<User:0x1030bc828>

Am I able to cross model-collection boundaries in this manner?

  • 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-15T07:12:50+00:00Added an answer on May 15, 2026 at 7:12 am

    To access a user‘s profile, you have to use something like

    @user = User.visible(:include => :profiles)
    @user.first.profile
    

    Or, if what you want is all full_names, I believe you should do something like

    # untested
    User.visible(:include=> :profiles).map(&:profile).collect{ |p| p.full_name }
    

    But probably there’s a better way… It doesn’t look pretty =P

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

Sidebar

Related Questions

Two models (Rails 2.3.8): User; username & disabled properties; User has_one :profile Profile; full_name
I have two models in Rails 3 - a User model and a Profile
I'm trying to establish a relationship between two models in Rails but I am
I have two models, TreeNode and User. Each user has_one TreeNode, which is the
So I have two rails models - user and role - each specified with
I am developing a rails application in which I have two models User and
I have two models with a one-to-one association. class User < ActiveRecord::Base has_one :setting
I have two models in my Ruby on Rails app: User and Bookcase. I've
We have two Rails models: Person and Administrator . We're disallowing removal of Administrator
In my Rails 3.2 models directory, I have a folder foo containing two classes:

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.