Пользовательская модель Ruby on rails может создать команду и стать лидером или присоединиться к существующей команде в качестве члена - PullRequest
0 голосов
/ 21 ноября 2018

Привет, ребята, я работаю над приложением rails, где пользователи, которые успешно зарегистрировались и вошли в свою панель, могут создать команду и стать лидером (пригласить других присоединиться по электронной почте, удалить существующих участников и т. Д.) Или присоединиться к существующему.команда как участник. (могу просматривать только других участников и информацию о себе). Я использую гем Devise для входа в систему / регистрации, так как в нем много всего, что мне нужно.Команда имеет одного менеджера и много членов.Вот что я попробовал: пользователи принадлежат к командам, а у команд много пользователей.Я также попробовал ассоциацию, у пользователей есть одна команда, и у команд есть много пользователей, но один менеджер.Я очень смущен, спасибо еще раз.

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
   belongs_to :team 
end

schema.rb

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.string "middlename"
    t.string "lastname"
    t.string "phone"
    t.string "city"
    t.string "state"
    t.string "street"
    t.string "zip"
    t.bigint "team_id"
    t.index ["team_id"], name: "index_users_on_team_id"
    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
  has_many :users, class_name: "User"  
end

rout.rb

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