Employer registration I have two registration paths in my app. They are very similar and I am curious if I should simplify 4 associated actions down into two actions that handle the same amount of work.

Here are my controller actions:

def employer_registration
  @employer_signup = EmployerSignup.new
end

def employee_registration
  @employee_signup = EmployeeSignup.new
end

def create_employee
  @employee_signup = EmployeeSignup.new(params[:employee_signup])

  if @employee_signup.save
    sign_in @employee_signup.user
    redirect_to root_path, notice: 'You signed up successfully'
  else
    render action: :employee_registration
  end
end

def create_employer
  @employer_signup = EmployerSignup.new(params[:employer_signup])

  if @employer_signup.save
    sign_in @employer_signup.user
    redirect_to root_path, notice: 'You signed up successfully.'
  else
    render action: :employer_registration
  end
end


As you can see, the only difference between the two registration paths are the form object that's being used, EmployeeSignup and EmployerSignup respectively.  As you would expect, views are actually very similar too, they just display a form that's appropriate to each form object.

I have full test suits for each of these registration paths and it seems like an exceptionally large amount of duplication.

Each path handles something different, one handles employees registering, the other handles employers - so I'm tempted to leave them separate.  But, if thought of another way, they both handle one idea: User Registration.  In that case I feel it would be wiser to reconcile the different paths into one path and have a simple parameter control which form object is being used depending on the desired path.

Is my code acceptable as is or would it be more reasonable to refactor it down into one 'new' action and one 'create' action?
Your setup is going to eventually be working around Rails configurations, which are built for the canonical index, new, create, show, edit, update, delete.

Rails does resource routing for this very reason (read more in the Rails Guide on Routing). It's also very in-line with HTTP verb standards and will make turning this into a JSON API trivial, should you need one.

Since your Employer and Employee are separate domain objects, I would make them separate controllers. This leaves some nice future options for other actions when you need them like edit and destroy.

class EmployerController &lt; ApplicationController
  def new
    @employer_signup = EmployerSignup.new
  end

  def create
    @employer_signup = EmployerSignup.new(params[:employer_signup])

    if @employer_signup.save
      sign_in @employer_signup.user
      redirect_to root_path, notice: 'You signed up successfully.'
    else
      render action: :employer_registration
    end
  end
end

class EmployeeController &lt; ApplicationController
  def new
    @employee_signup = EmployeeSignup.new
  end

  def create
    @employee_signup = EmployeeSignup.new(params[:employee_signup])

    if @employee_signup.save
      sign_in @employee_signup.user
      redirect_to root_path, notice: 'You signed up successfully'
    else
      render action: :employee_registration
    end
  end
end