Sorry if this is totally obvious, but I'm a Rails beginner and am having a really tough time finding the answer to this question.
I'm receiving an AbstractController::DoubleRenderError on my create action, which should simultaneously create a new user (taking in their email address, password, and password confirmation) and create a new profile (which takes in a number of other preferences I ask users to select when creating an account). I basically want to get back the user and profile jsons if they're both successfully created, and receive errors if they're not.
I know the error I'm getting is due to the double "render json" lines I have (one block under the if, one block under the else), but cannot seem to determine how to get these two lines into one.
def create
@user = User.new(register_params)
@profile = Profile.new(profile_params)
if @user.save && @profile.save
render json: @user, status: :created, location: @user
render json: @profile, status: :created, location: @profile
else
render json: @user.errors, status: :unprocessable_entity
render json: @profile.errors, status: :unprocessable_entity
end
end
Thank you in advance!