We've moved discussions to Discord

Using a Different team.name for Teams

Ryan Chin
Hi, all!

My use case is that I'm trying to create an app like a Slack, or Zendesk, where a person signs up for an account and they get their own instance of the app via a subdomain (i.e. mycompanyname.slack.com).  

I'm trying to manipulate Team to represent an account.  Obviously with something like an instance of Slack or Zendesk, the user will want to specify a different identifier for the instance than their name.  Currently, a Team is created by using the name of the person signing up, and I'm trying to change that by adding a field in the user registration for subdomain.  However, I'm having trouble making it work.

When I'm posting, it's rolling back.  The User and Team aren't creating.  Can someone please help?  Thank you in advance!

Here's the trace:
Started POST "/users" for ::1 at 2019-07-30 13:17:10 -0700
Processing by Users::RegistrationsController#create as JS
  Parameters: {"authenticity_token"=>"CSsYDyDW5nm95wXIYFrkNnr4SL3lVj3aiRpEEGg4mc14c2DGNtW8PQrPNQVoU5ZHhpyBmHkrgfP+H4erpzWAoQ==", "user"=>{"name"=>"[FILTERED]", "email"=>"[FILTERED]", "subdomain"=>"mycompany", "password"=>"[FILTERED]", "time_zone"=>"Pacific Time (US & Canada)", "terms_of_service"=>"1"}, "button"=>""}
   (0.5ms)  BEGIN
  User Exists? (0.6ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "foo@test.com"], ["LIMIT", 1]]
  User Create (0.7ms)  INSERT INTO "users" ("email", "encrypted_password", "confirmed_at", "first_name", "last_name", "time_zone", "accepted_terms_at", "accepted_privacy_at", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"  [["email", "foo@test.com"], ["encrypted_password", "$2a$11$s2Q5u1ts6A1WatFZj2a60uncrQ3s7HEXteiZ57ID3Xsvvou8zpnuO"], ["confirmed_at", "2019-07-30 20:17:10.603751"], ["first_name", "Foo"], ["last_name", "Bar"], ["time_zone", "Pacific Time (US & Canada)"], ["accepted_terms_at", "2019-07-30 20:17:10.603509"], ["accepted_privacy_at", "2019-07-30 20:17:10.603542"], ["created_at", "2019-07-30 20:17:10.603650"], ["updated_at", "2019-07-30 20:17:10.603650"]]
  Team Load (0.4ms)  SELECT "teams".* FROM "teams" WHERE "teams"."owner_id" = $1 LIMIT $2  [["owner_id", 11], ["LIMIT", 1]]
  ↳ app/models/concerns/user_teams.rb:18:in `create_personal_team'
  Team Exists? (0.4ms)  SELECT 1 AS one FROM "teams" WHERE "teams"."subdomain" = $1 LIMIT $2  [["subdomain", "mycompany"], ["LIMIT", 1]]
  ↳ app/models/concerns/user_teams.rb:22:in `create_personal_team'
   (0.3ms)  ROLLBACK
Redirected to http://www.localhost:3000/users
Completed 200 OK in 170ms (ActiveRecord: 10.4ms | Allocations: 36656)

Here are my changes:
# views/devise/registrations/new.html.erb (added code)
    <div class="form-group">      
      <%= f.label :subdomain %>      
      <%= f.text_field :subdomain,  autocomplete: "subdomain", placeholder: "Company name used for your team's site (i.e. yourcompany.test.com)", class: "form-control" %>    

# application controller (modified a line)
def configure_permitted_parameters      extra_keys  = [:avatar, :name, :time_zone, :subdomain]

# user.rb (added code)
attribute :subdomain

# user_teams.rb (modified code)
    team = build_personal_team name: name subdomain: subdomain, personal: true
Dan Weaver
Not related to your question, but maybe the <pre> tags in forum posts should have a fixed width and horizontal scrolling? 🤔
this is really really  Brian Cliette  
You’re not receiving notifications from this thread.