Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Rails 4. Update User when creating different model.

Just to show you how I got to this point:

Every user has many profiles. Every profile has type recognized by single table inheritance(amateur, professional, and some other). I need to store current_profile somewhere and somehow.

Professionals Controller

class ProfessionalsController < ApplicationController
def create
  @professional = Professional.new(professional_params)
  @user = current_user
  @professional.user_id = current_user.id
  @update_current_profile = User.update(@user, {:current_profile => @professional.id})
  if @professional.save




  def professional_params
    params.require(:professional).permit(:id, :username, :user_id)


This is meant to update current_profile of user to the newly created professional profile and do some staff then.

When the profile is created current_profile is set(updated) to NULL. If I change :

@update_current_profile = User.update(@user, {:current_profile => @professional.id})

to something different, for example:

@update_current_profile = User.update(@user, {:current_profile => @professional.user_id})


@update_current_profile = User.update(@user, {:current_profile => 3})

it stores data in User.current_profile perfectly.

I was trying @professional without an .id too. Why is this doing so?

Another question is. Is this the best way to store current_profile of user? Would you recommend me any better/safer/more efficient solution?

Thanks all of you guys.