1
I have two models. One called User and the other 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 is that every professional will be a user. Therefore, every time I register a professional, I need to automatically 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 professional user at the time of the creation of the professional. I can save the professional normally, but no user is created for him or assigned their respective user_id.
What am I doing wrong? Any advice for this kind of situation?