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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:58:36+00:00 2026-06-16T13:58:36+00:00

I have 2 models – User model and Profile model. I have setup the

  • 0

I have 2 models – User model and Profile model. I have setup the relationship as follows:

class User
  has_one :profile
end

class Profile
  belongs_to :user
end

I have a profiles controller with 4 actions – new create edit and update. Once the User signs up or logs in he is redirected to the New action in the Profiles controller. From here how do I create a profile for that user? Specifically what should I have in my New action and Create action. Right now the route for the new action is just profiles/new which doesn’t capture the Users params. I am trying to do this but its failing.

Profiles Controller

def new
    @user = User.find(params[:id])
    @profile = @user.build_profile
  end

  def create
    @profile = current_user.build_profile(params[:profile])
    if @profile.save
      redirect_to current_user
    else
      render new
    end
  end
  • 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-16T13:58:37+00:00Added an answer on June 16, 2026 at 1:58 pm

    the new action in the profile controller doesn’t need to get the id of the user from the params.
    So your controller would be like this

    def new
      @user = current_user
      @profile = @user.build_profile
    end
    
    def create
      @profile = current_user.build_profile(params[:profile])
      if @profile.save
        redirect_to current_user
      else
        render new
      end
    end
    

    actually sending the id of the user to the new action could be a security hole as I could send the id of another user and create a profile for some other user in the system, which shouldn’t be allowed.

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

Sidebar

Related Questions

I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
Suppose i have : models.py: class Person(models.Model): user = models.OneToOneField(User) def get_album(self): return self.album_set.all()
I have models as follows: class Place(models.Model): name = models.CharField(max_length=300) class Person(models.Model): name =
I have models as follows: class Book(models.Model): title = models.CharField(max_length=400) def transactions_all_time(self): latest_transactions =
I'm using Devise and have models set up like this: User has_one :profile Profile
I have models: class Model < ActiveRecord::Base has_many :model2 end class Model2 < ActiveRecord::Base
I have models for eg like this class Model(): time=models.DateTimeField() free=models.BooleanField(default=False) user=models.ForeignKey(User) //it is
I have models: class User < ActiveRecord::Base has_many :user_skills end class UserSkill < ActiveRecord::Base
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =

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.