質問編集履歴

1

質問修正

2017/04/01 08:35

投稿

innjera
innjera

スコア132

test CHANGED
@@ -1 +1 @@
1
- erbからapplication_helper機能切り出し
1
+ application_helper / content_tagメソッドを使ったスペース表示
test CHANGED
@@ -1,8 +1,12 @@
1
- `erb`の以下記載が何となく見通し悪くしているので、`application_helper`に制御を切り出しのですが、その原因の殆どが`font awesom`の`icon`の表示なので難しい(あり意味ない)でしょうか? 何かヒントあればご教示頂きたくお願い致します。
1
+ `erb`の以下記載が何となく見通し悪くしているので、`application_helper`に制御を切り出しいます。
2
+
3
+ `erb`内に記載ある`&nbsp(半角スペース)`を`helper`内の`content_tag`メソッドで使用するにはどうすれば良いのでしょうか?
2
4
 
3
5
 
4
6
 
5
7
  ```html
8
+
9
+ #erbを使用
6
10
 
7
11
  <% @adviser.lessons.each do |lesson| %>
8
12
 
@@ -28,8 +32,6 @@
28
32
 
29
33
 
30
34
 
31
- 色々tryしましたが、うまくいきません。
32
-
33
35
  ```ruby
34
36
 
35
37
  #application_helper.rb
@@ -38,16 +40,18 @@
38
40
 
39
41
  def vote_count(lesson)
40
42
 
41
- if lesson.votes.present?
43
+ if lesson.votes.blank?
42
44
 
43
- lesson.votes.count
45
+ content_tag(:span, content_tag(:i, "", class: "fa fa-heart-o", "aria-hidden" => "true"), class: "top-like")
44
46
 
45
- elsif
47
+ else
48
+
49
+ count = lesson.votes.count
50
+
51
+ content_tag(:span, content_tag(:i, count, class: "fa fa-heart"), class: "top-like")
52
+
53
+ end
46
54
 
47
55
  end
48
56
 
49
- end
50
-
51
-
52
-
53
57
  ```