Come up with an apartment building app

My application is currently allowing the user sign_in to his subdomain ie subdomain.domain.com/users/sign_in. I would like users to visit domain.com/users/sign_in.

I am new to Rails and I got a lot of help regarding subdomains from this project on Github: https://github.com/appcasts/saas-timetracker

In routes.rb, I added "devise_for: users" to show the sign_in form on domain.com/users/sign_in, however I cannot authenticate the user in the subdomain because I get an "Invalid email address and password".

Is there a way that users can log in with domain.com and be authenticated and redirected to their correct subdomain?

I tried: A practical guide. Entering a registration area in a subdomain

And I get the column, the "subdomain" does not exist. I also tried the Custom_Failure_app solution, which all the time gave me an error for all the redirect_to paths that I add.

Any help or suggestions would be appreciated.

+4
source share
1 answer

In our application, we create a user using

def create 
  @user = User.new(user_params)
  @account = Account.new(subdomain: params[:subdomain], owner: @user)
  if @user.valid? && @account.valid?
    Apartment::Tenant.create(@account.subdomain)
    Apartment::Tenant.switch(@account.subdomain)
    @user.save
    @account.save
    redirect_to new_user_session_url(subdomain: @account.subdomain)
  end 
end

In the create method on the controller account.

https://github.com/DefactoSoftware/Hours/blob/development/app/controllers/accounts_controller.rb

+4

All Articles