I have 2 models Users and Companies. (I'm using Devise for User)
- User belongs to Company.
- Company has many Users.
My User model includes an client_id column.
At the moment a User signs-up and is directed to the new_company_path where I'd like to create the relationship. (I'd prefer to keep this in 2 steps).
I know my code is wrong here in the companies_controller.rb — but it's where I'm at
def create
@user = current_user
@company = @user.Company.new(params[:company])
respond_to do |format|
if @company.save
format.html { redirect_to root_path, notice: 'Company was successfully created.' }
format.json { render json: @company, status: :created, location: @company }
else
format.html { render action: "new" }
format.json { render json: @company.errors, status: :unprocessable_entity }
end
end