I have two models. One called User and another called Professional, where:
#user.rb
class User < ActiveRecord::Base
has_one :professional
accepts_nested_attributes_for :professional
end
and
#professional.rb
class Professional < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user
end
My business rule says that every professional will be a user. Therefore, every time I register a professional, I automatically need to create a user and assign it to the respective professional. In my ProfessionalsController, in the action of new and create I did the following:
#Professionals_controller.rb
class ProfessionalsController < ApplicationController
def new
@professional = Professional.new
@professional.build_user
respond_with(@professional)
end
def create
@professional = Professional.new(professional_params)
@professional.save
respond_with(@professional)
end
end
The problem is that this way I can not create the user of the professional when the professional is created. I can save the professional normally, but no user is created for it nor assigned to its user_id .
What am I doing wrong? Any advice for that kind of situation?