回答編集履歴

1

追記

2016/10/21 15:13

投稿

cameluby
cameluby

スコア891

test CHANGED
@@ -17,3 +17,183 @@
17
17
 
18
18
 
19
19
  これがどういう意味か分かりませんでした。
20
+
21
+
22
+
23
+ ---------------
24
+
25
+ _micropost.html.erbをusers_controllerとshops_controllerで共通で使用したいということであれば、
26
+
27
+ `controller_name`メソッドを使用して分岐することができます。
28
+
29
+ 質問者さんが追加した回答をみると、users_controllerの時は上の分岐、shops_controllerの時は下の分岐になっていますね。
30
+
31
+ なのでそれぞれ、
32
+
33
+ ```
34
+
35
+ <% if controller_name = "users" %> ←追加
36
+
37
+ ```
38
+
39
+
40
+
41
+ ```ruby
42
+
43
+ <% elsif controller_name = "shops" %> ←追加
44
+
45
+ ```
46
+
47
+ のようにしたら良さそうです。
48
+
49
+ controllerからは`@page`と`@account`の記述は消して構いません。
50
+
51
+
52
+
53
+ ただ、これだと共有できている部分が
54
+
55
+ ```html
56
+
57
+ <li id="micropost-<%= micropost.id %>">
58
+
59
+ </li>
60
+
61
+ ```
62
+
63
+ しか無いので、ファイル自体を分けても良いのかな?と思いますが。。。
64
+
65
+
66
+
67
+ ```ruby
68
+
69
+ # _micropost.html.erb
70
+
71
+
72
+
73
+ <li id="micropost-<%= micropost.id %>">
74
+
75
+ <% if controller_name = "users" %> ←追加
76
+
77
+ <!-- ユーザーアイコン -->
78
+
79
+ <%= link_to gravatar_for(micropost.user, size: 50), micropost.user %>
80
+
81
+ <!-- ユーザー名 -->
82
+
83
+ <span class="user"><%= link_to micropost.user.username, micropost.user %></span>
84
+
85
+ <span class="content">
86
+
87
+ <!-- 投稿文 -->
88
+
89
+ <%= micropost.content %>
90
+
91
+ <!-- 投稿写真 -->
92
+
93
+ <%= image_tag micropost.picture.url if micropost.picture? %>
94
+
95
+ </span>
96
+
97
+ <!-- 投稿時間 -->
98
+
99
+ <span class="timestamp">
100
+
101
+ Posted <%= time_ago_in_words(micropost.created_at) %> ago.
102
+
103
+ </span>
104
+
105
+
106
+
107
+ <!-- 削除リンク -->
108
+
109
+ <% if current_user?(micropost.user) %>
110
+
111
+ <%= link_to "delete", micropost, method: :delete, data: { confirm: "You sure?" } %>
112
+
113
+ <% end %>
114
+
115
+
116
+
117
+ <!-- お気に入り登録リンク user-to-user-->
118
+
119
+ <% if user_signed_in? %>
120
+
121
+ <% if !current_user?(micropost.user) %>
122
+
123
+ <div id="follow_form">
124
+
125
+ <%= render 'favorites/favorite_links', micropost: micropost %>
126
+
127
+ </div>
128
+
129
+ <% end %>
130
+
131
+ <% end %>
132
+
133
+
134
+
135
+ <% elsif controller_name = "shops" %> ←追加
136
+
137
+ <!-- ショップアイコン -->
138
+
139
+ <%= link_to gravatar_to(micropost.shop, size: 50), micropost.shop %>
140
+
141
+ <!-- ショップ名 -->
142
+
143
+ <span class="shop"><%= link_to micropost.shop.shopname, micropost.shop %></span>
144
+
145
+ <span class="content">
146
+
147
+ <!-- 投稿文 -->
148
+
149
+ <%= micropost.content %>
150
+
151
+ <!-- 投稿写真 -->
152
+
153
+ <%= image_tag micropost.picture.url if micropost.picture? %>
154
+
155
+ </span>
156
+
157
+ <!-- 投稿時間 -->
158
+
159
+ <span class="timestamp">
160
+
161
+ Posted <%= time_ago_in_words(micropost.created_at) %> ago.
162
+
163
+ </span>
164
+
165
+
166
+
167
+ <!-- 削除リンク -->
168
+
169
+ <% if current_shop?(micropost.shop) %>
170
+
171
+ <%= link_to "delete", micropost, method: :delete, data: { confirm: "You sure?" } %>
172
+
173
+ <% end %>
174
+
175
+
176
+
177
+ <!-- いいね!リンク shopver-to-shop -->
178
+
179
+ <% if shop_signed_in? %>
180
+
181
+ <% if !current_shop?(micropost.shop) %>
182
+
183
+ <div id="follow_form">
184
+
185
+ <%= render 'likes/like_links', micropost: micropost %>
186
+
187
+ </div>
188
+
189
+ <% end %>
190
+
191
+ <% end %>
192
+
193
+
194
+
195
+ <% end %>
196
+
197
+ </li>
198
+
199
+ ```