質問編集履歴
2
s
test
CHANGED
File without changes
|
test
CHANGED
@@ -152,7 +152,7 @@
|
|
152
152
|
|
153
153
|
class Post < ApplicationRecord
|
154
154
|
|
155
|
-
# userと1:nの紐付け
|
155
|
+
# userprofileと1:nの紐付け
|
156
156
|
|
157
157
|
belongs_to :user_profile
|
158
158
|
|
1
codeを該当部分に載せさせて頂きました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -101,3 +101,117 @@
|
|
101
101
|
end
|
102
102
|
|
103
103
|
```
|
104
|
+
|
105
|
+
```Ruby
|
106
|
+
|
107
|
+
class User < ApplicationRecord
|
108
|
+
|
109
|
+
# Include default devise modules. Others available are:
|
110
|
+
|
111
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
112
|
+
|
113
|
+
devise :database_authenticatable, :registerable,
|
114
|
+
|
115
|
+
:recoverable, :rememberable, :validatable
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
# user_profleモデルと1:1の紐付け
|
120
|
+
|
121
|
+
has_one :user_profile, dependent: :destroy
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
```Ruby
|
130
|
+
|
131
|
+
class UserProfile < ApplicationRecord
|
132
|
+
|
133
|
+
# userモデルと1:1の紐付け
|
134
|
+
|
135
|
+
belongs_to :user
|
136
|
+
|
137
|
+
# postモデルと1:nの紐付け
|
138
|
+
|
139
|
+
has_many :posts, dependent: :destroy
|
140
|
+
|
141
|
+
# carrierwave
|
142
|
+
|
143
|
+
mount_uploader :image, ImageUploader
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
```Ruby
|
152
|
+
|
153
|
+
class Post < ApplicationRecord
|
154
|
+
|
155
|
+
# userと1:nの紐付け
|
156
|
+
|
157
|
+
belongs_to :user_profile
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
```
|
164
|
+
|
165
|
+
```Ruby
|
166
|
+
|
167
|
+
showusers/index
|
168
|
+
|
169
|
+
<h1>エンドユーザトップページ</h1>
|
170
|
+
|
171
|
+
<%= @user.name %>
|
172
|
+
|
173
|
+
<% @post.each do |post| %>
|
174
|
+
|
175
|
+
<div class="card card-body bg-light">
|
176
|
+
|
177
|
+
<div class="title">
|
178
|
+
|
179
|
+
<%= link_to user_profile_path(post.id) do %>
|
180
|
+
|
181
|
+
<%= post.title %>
|
182
|
+
|
183
|
+
<% end %>
|
184
|
+
|
185
|
+
</div>
|
186
|
+
|
187
|
+
<div class="active_area">
|
188
|
+
|
189
|
+
活動地域: <%= post.user_profile.active_area %>
|
190
|
+
|
191
|
+
</div>
|
192
|
+
|
193
|
+
<div class="language">
|
194
|
+
|
195
|
+
言語:
|
196
|
+
|
197
|
+
</div>
|
198
|
+
|
199
|
+
<div class="experience">
|
200
|
+
|
201
|
+
経験年数:
|
202
|
+
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div class="text">
|
206
|
+
|
207
|
+
<%= post.text %>
|
208
|
+
|
209
|
+
</div>
|
210
|
+
|
211
|
+
</div>
|
212
|
+
|
213
|
+
<% end %>
|
214
|
+
|
215
|
+
<p>--------------<br></p>
|
216
|
+
|
217
|
+
```
|