これらを正しく行っているかどうかはわかりません。
アカウント、ユーザー、イベントの 3 つのモデルがあります。
アカウントにはユーザーのグループが含まれています。各ユーザーは、ログイン用の独自のユーザー名とパスワードを持っていますが、同じアカウントで同じアカウント データにアクセスできます。
イベントはユーザーによって作成され、同じアカウント内の他のユーザーもそれを読み取ったり編集したりできます。
次の移行とモデルを作成しました。
ユーザーの移行
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.integer :account_id
t.string :username
t.string :password
t.timestamps
end
end
def self.down
drop_table :users
end
end
アカウントの移行
class CreateAccounts < ActiveRecord::Migration
def self.up
create_table :accounts do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :accounts
end
end
イベントの移行
class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.integer :account_id
t.integer :user_id
t.string :name
t.string :location
t.timestamps
end
end
def self.down
drop_table :events
end
end
アカウント モデル
class Account < ActiveRecord::Base
has_many :users
has_many :events
end
ユーザーモデル
class User < ActiveRecord::Base
belongs_to :account
end
イベントモデル
class Event < ActiveRecord::Base
belongs_to :account
belongs_to :user
end
それで....
- この設定は正しいですか?
- ユーザーが新しいアカウントを作成するたびに、システムはユーザー情報 (ユーザー名やパスワードなど) を尋ねます。それらを正しいテーブルに追加するにはどうすればよいですか?
- 新しいイベントを追加するにはどうすればよいですか?
このような長い質問で申し訳ありません。このようなデータ構造を処理するレールの方法がよくわかりません。私に答えてくれてありがとう。:)