質問編集履歴
2
中間モデルを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,9 +92,7 @@
|
|
92
92
|
|
93
93
|
devise_for :users
|
94
94
|
|
95
|
-
get 'records/index'
|
96
|
-
|
97
|
-
root '
|
95
|
+
root 'records#index'
|
98
96
|
|
99
97
|
resources :users, only: [:edit, :update]
|
100
98
|
|
@@ -122,26 +120,6 @@
|
|
122
120
|
|
123
121
|
|
124
122
|
|
125
|
-
|
126
|
-
|
127
|
-
def after_sign_in_path_for(resource)
|
128
|
-
|
129
|
-
records_index_path # ログイン後に遷移するpathを設定
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
def after_sign_out_path_for(resource)
|
136
|
-
|
137
|
-
new_user_session_path # ログアウト後に遷移するpathを設定
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
123
|
protected
|
146
124
|
|
147
125
|
|
@@ -207,3 +185,19 @@
|
|
207
185
|
end
|
208
186
|
|
209
187
|
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
中間モデル family_user.rb
|
192
|
+
|
193
|
+
```Ruby
|
194
|
+
|
195
|
+
class FamilyUser < ApplicationRecord
|
196
|
+
|
197
|
+
belongs_to :family
|
198
|
+
|
199
|
+
belongs_to :user
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
```
|
1
FamilyモデルとUserモデルを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -155,3 +155,55 @@
|
|
155
155
|
end
|
156
156
|
|
157
157
|
```
|
158
|
+
|
159
|
+
Familyモデル
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
```Ruby
|
164
|
+
|
165
|
+
class Family < ApplicationRecord
|
166
|
+
|
167
|
+
def change
|
168
|
+
|
169
|
+
create_table :families do |t|
|
170
|
+
|
171
|
+
has_many :family_users
|
172
|
+
|
173
|
+
has_many :users, through: :family_users
|
174
|
+
|
175
|
+
validates :name, presence: true, uniqueness: true
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
Userモデル
|
186
|
+
|
187
|
+
```Ruby
|
188
|
+
|
189
|
+
class User < ApplicationRecord
|
190
|
+
|
191
|
+
# Include default devise modules. Others available are:
|
192
|
+
|
193
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
194
|
+
|
195
|
+
devise :database_authenticatable, :registerable,
|
196
|
+
|
197
|
+
:recoverable, :rememberable, :validatable
|
198
|
+
|
199
|
+
validates :name, presence: true, uniqueness: true
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
has_many :family_users
|
204
|
+
|
205
|
+
has_many :families, through: :family_users
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
```
|