質問編集履歴
1
ソースコードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,16 +10,94 @@
|
|
10
10
|
userにも新規記事登録ボタンが表示される
|
11
11
|
|
12
12
|
### 該当のソースコード
|
13
|
-
|
13
|
+
views>articles>_article.html.erb
|
14
14
|
```ここに言語名を入力
|
15
|
+
<%= link_to article_path(article) do %>
|
16
|
+
<div class="card">
|
17
|
+
<% if article.eyecatch.attached? %>
|
18
|
+
<div class="card_image">
|
19
|
+
<%= image_tag article.eyecatch %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
22
|
+
<div class="card_content">
|
23
|
+
<div class="card_title">
|
15
|
-
<%
|
24
|
+
<%= article.title %>
|
25
|
+
</div>
|
16
|
-
|
26
|
+
<div class="card_detail">
|
27
|
+
<div>
|
17
|
-
|
28
|
+
<p><%= article.company.display_name %></p>
|
18
|
-
|
29
|
+
<p><%= article.display_created_at %></p>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</div>
|
19
33
|
</div>
|
34
|
+
<% if company_signed_in? %>
|
35
|
+
<div class="card_heart">
|
36
|
+
<%= image_tag 'heart.svg' %>
|
37
|
+
<span><%= article.like_count %></span>
|
38
|
+
</div>
|
39
|
+
<% end %>
|
20
40
|
<% end %>
|
21
41
|
```
|
22
42
|
|
43
|
+
models>user.rb
|
44
|
+
```ここに言語を入力
|
45
|
+
class User < ApplicationRecord
|
46
|
+
# Include default devise modules. Others available are:
|
47
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
48
|
+
devise :database_authenticatable, :registerable,
|
49
|
+
:recoverable, :rememberable, :validatable
|
50
|
+
|
51
|
+
has_many :likes, dependent: :destroy
|
52
|
+
has_many :favorite_articles, through: :likes, source: :article
|
53
|
+
has_one :profile, dependent: :destroy
|
54
|
+
|
55
|
+
delegate :birthday, :age, :gender, to: :profile, allow_nil: true
|
56
|
+
|
57
|
+
def has_liked?(article)
|
58
|
+
likes.exists?(article_id: article.id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def display_name
|
62
|
+
profile&.nickname || self.email.split('@').first
|
63
|
+
end
|
64
|
+
|
65
|
+
def prepare_profile
|
66
|
+
profile || build_profile
|
67
|
+
end
|
68
|
+
|
69
|
+
def avatar_image
|
70
|
+
if profile&.avatar&.attached?
|
71
|
+
profile.avatar
|
72
|
+
else
|
73
|
+
'default-avatar.png'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
```
|
79
|
+
|
80
|
+
model.company.rb
|
81
|
+
```
|
82
|
+
class Company < ApplicationRecord
|
83
|
+
# Include default devise modules. Others available are:
|
84
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
85
|
+
devise :database_authenticatable, :registerable,
|
86
|
+
:recoverable, :rememberable, :validatable
|
87
|
+
|
88
|
+
has_many :articles, dependent: :destroy
|
89
|
+
|
90
|
+
def has_written?(article)
|
91
|
+
articles.exists?(id: article.id)
|
92
|
+
end
|
93
|
+
|
94
|
+
def display_name
|
95
|
+
self.email.split('@').first
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
```
|
100
|
+
|
23
101
|
### 試したこと
|
24
102
|
|
25
103
|
if文を使いcompany_signed_in?やcurrent_companyで試しましたができませんでした。
|