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

  • Home
  • SEARCH
  • 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 7027217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:13:09+00:00 2026-05-28T00:13:09+00:00

I would like to access profiles table from my Profile model which belongs_to :user

  • 0

I would like to access “profiles” table from my Profile model which belongs_to :user “User model”.

Firstly in my show action of the users_controller I’d like to grab data from the profiles table in order to show on the users profile page.

Secondly I’d like to make it possible for users to edit these things using a form. I know this is done in the update action? while edit action makes it possible to show a form on the edit view page..

Here is my controller:

class UsersController < ApplicationController



  def new
    @user = User.new 
    @title = "Practice"
  end

  def create
    @user = User.new(params[:user])   
    respond_to do |format|
      if @user.save 
        @user.build_profile.save #same as Profile.new(:user_id => @user.id)
        login @user
        UserMailer.join_confirmation(@user).deliver
        format.js   { render :js => "window.location = '#{root_path}'" } 
        flash[:notice] = "Welcome!"
      else

        format.js   { render :form_errors }
      end
    end
  end

  def show

  end

  def update

  end

  def edit

  end



end

1) How would I access my profiles table?
The User has_one :profile
The Profile belongs_to :user

Advice will be appreciated. Took me half of the day to figure out how to have a row corresponding to a newly created user at sign up created in the profiles table and now the next step is to be able to grab data from the model in my users_controller. i know I could just create a profiles_controller and do things there but I don’t want to attempt that right now as I’m sure there’s a way to do it via the users_controller.

Thanks in advance for advice given.

View:

<%= @profile_data.first_name %>

<h4><%= current_user.username.capitalize %></h4>
<%= gravatar_image_tag(current_user.email, :alt => @title, :class => "gravatar", :gravatar => { :size => 150 }) %>
<br />

Trying to pull first_name from profiles table through users_controller

  def show
    @user = User.find_by_username(params[:username])
    @profile_data = @user.profile

  end

route:

  match ':username' => "users#show"

I expect to see the name stored in first_name column of the profiles table when i visit localhost:3000/username

it doesn’t show the users first name.

  • 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-28T00:13:09+00:00Added an answer on May 28, 2026 at 12:13 am

    You can just do:

    @user.profile
    

    That will return the profile belonging to the User

    Otherwise:

    Profile.where('whatever condition you fancy')
    

    will return A profile object based on conditions

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

Sidebar

Related Questions

I would like to access my AudioUnit Component Kernel members from an action method
I would like to access a web page from a python program. I have
I would like to access the Rails session secret programmatically (I am using it
I would like to access micro-state accounting timers programmatically on Linux. I guess the
I would like to access a class everywhere in my application, how can I
I would like to access the work items in our TFS programmatically. Shouldn't there
I would like to access information on the logical drives on my computer using
I would like to access a MySQL database using PHP. Can someone please explain
In my Servlet I would like to access the root of the context so
I'm running a wordpress blog and would like to access the actual file that

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.