質問編集履歴
1
ソースコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,26 +22,182 @@
|
|
22
22
|
|
23
23
|
### 該当のソースコード
|
24
24
|
|
25
|
-
|
25
|
+
views>articles>_article.html.erb
|
26
26
|
|
27
27
|
```ここに言語名を入力
|
28
28
|
|
29
|
+
<%= link_to article_path(article) do %>
|
30
|
+
|
31
|
+
<div class="card">
|
32
|
+
|
33
|
+
<% if article.eyecatch.attached? %>
|
34
|
+
|
35
|
+
<div class="card_image">
|
36
|
+
|
37
|
+
<%= image_tag article.eyecatch %>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
<div class="card_content">
|
44
|
+
|
45
|
+
<div class="card_title">
|
46
|
+
|
29
|
-
<% i
|
47
|
+
<%= article.title %>
|
48
|
+
|
30
|
-
|
49
|
+
</div>
|
50
|
+
|
31
|
-
<div class="card_
|
51
|
+
<div class="card_detail">
|
52
|
+
|
32
|
-
|
53
|
+
<div>
|
54
|
+
|
33
|
-
<%= ima
|
55
|
+
<p><%= article.company.display_name %></p>
|
34
|
-
|
56
|
+
|
35
|
-
<
|
57
|
+
<p><%= article.display_created_at %></p>
|
58
|
+
|
59
|
+
</div>
|
60
|
+
|
61
|
+
</div>
|
62
|
+
|
63
|
+
</div>
|
36
64
|
|
37
65
|
</div>
|
38
66
|
|
67
|
+
<% if company_signed_in? %>
|
68
|
+
|
69
|
+
<div class="card_heart">
|
70
|
+
|
71
|
+
<%= image_tag 'heart.svg' %>
|
72
|
+
|
73
|
+
<span><%= article.like_count %></span>
|
74
|
+
|
75
|
+
</div>
|
76
|
+
|
77
|
+
<% end %>
|
78
|
+
|
39
79
|
<% end %>
|
40
80
|
|
41
81
|
```
|
42
82
|
|
43
83
|
|
44
84
|
|
85
|
+
models>user.rb
|
86
|
+
|
87
|
+
```ここに言語を入力
|
88
|
+
|
89
|
+
class User < ApplicationRecord
|
90
|
+
|
91
|
+
# Include default devise modules. Others available are:
|
92
|
+
|
93
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
94
|
+
|
95
|
+
devise :database_authenticatable, :registerable,
|
96
|
+
|
97
|
+
:recoverable, :rememberable, :validatable
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
has_many :likes, dependent: :destroy
|
102
|
+
|
103
|
+
has_many :favorite_articles, through: :likes, source: :article
|
104
|
+
|
105
|
+
has_one :profile, dependent: :destroy
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
delegate :birthday, :age, :gender, to: :profile, allow_nil: true
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
def has_liked?(article)
|
114
|
+
|
115
|
+
likes.exists?(article_id: article.id)
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
def display_name
|
122
|
+
|
123
|
+
profile&.nickname || self.email.split('@').first
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def prepare_profile
|
130
|
+
|
131
|
+
profile || build_profile
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
def avatar_image
|
138
|
+
|
139
|
+
if profile&.avatar&.attached?
|
140
|
+
|
141
|
+
profile.avatar
|
142
|
+
|
143
|
+
else
|
144
|
+
|
145
|
+
'default-avatar.png'
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
model.company.rb
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
class Company < ApplicationRecord
|
164
|
+
|
165
|
+
# Include default devise modules. Others available are:
|
166
|
+
|
167
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
168
|
+
|
169
|
+
devise :database_authenticatable, :registerable,
|
170
|
+
|
171
|
+
:recoverable, :rememberable, :validatable
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
has_many :articles, dependent: :destroy
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
def has_written?(article)
|
180
|
+
|
181
|
+
articles.exists?(id: article.id)
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def display_name
|
188
|
+
|
189
|
+
self.email.split('@').first
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
|
200
|
+
|
45
201
|
### 試したこと
|
46
202
|
|
47
203
|
|