I have a Domain model for creating the tenant.
class Domain < ApplicationRecord
after_create :create_tenant
def create_tenant
Apartment::Tenant.create(name)
end
end
After creating the tenant "example" i want to redirect my browser automatically to http://example.lvh.me:3000
Can someone help me with this?
The answer was easy than I thought . Simply redirect to the url with your subdomain name after successful tenant creation. The modifying the create definition in domain controller
def create
@domain = Domain.new(domain_params)
respond_to do |format|
if @domain.save
format.html { redirect_to "http://#{@domain.name}.lvh.me:3000/users/sign_in", notice: 'Domain was successfully created.' }
else
format.html { render :new }
format.json { render json: @domain.errors, status: :unprocessable_entity }
end
end
end
Added this line
redirect_to "http://#{@domain.name}.lvh.me:3000/users/sign_in"