Пользователь создает команду или присоединяется к команде после регистрации / входа - PullRequest
0 голосов
/ 23 ноября 2018

В настоящее время я работаю над приложением Ruby on Rails, в котором пользователь устройства при успешном входе в систему / регистрации может создать команду или присоединиться к ней.Пользователь, который создает команду, становится ее владельцем и не может принадлежать другим командам. Пользователь, который решит присоединиться к команде, увидит все созданные команды и сможет присоединиться к ним.У меня много проблем с пониманием отношений, которые мне нужно использовать для этого

user.rb

class User < ApplicationRecord
   devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable, :confirmable 
   validates_presence_of :phone, :city, :state, :street, :zip, presence: true, on: :create
      has_one :team     
end

schema.rb

  create_table "teams", force: :cascade do |t|
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "team_name"
  end

create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string "firstname"
    t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

team.rb

class Team < ApplicationRecord
  belongs_to :user, class_name: 'User'  
end

rout.rb

   devise_for :users, path: 'users' , controllers: { sessions: "users/sessions", confirmations: 'users/confirmations', registrations: 'users/registrations' } 

Использую ли я правоподходит?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...