teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

質問修正

2017/04/01 08:35

投稿

innjera
innjera

スコア132

title CHANGED
@@ -1,1 +1,1 @@
1
- erbからapplication_helper機能切り出し
1
+ application_helper / content_tagメソッドを使ったスペース表示
body CHANGED
@@ -1,6 +1,8 @@
1
- `erb`の以下記載が何となく見通し悪くしているので、`application_helper`に制御を切り出しのですが、その原因の殆どが`font awesom`の`icon`の表示なので難しい(あり意味ない)でしょうか? 何かヒントあればご教示頂きたくお願い致します。
1
+ `erb`の以下記載が何となく見通し悪くしているので、`application_helper`に制御を切り出しいます。
2
+ `erb`内に記載ある`&nbsp(半角スペース)`を`helper`内の`content_tag`メソッドで使用するにはどうすれば良いのでしょうか?
2
3
 
3
4
  ```html
5
+ #erbを使用
4
6
  <% @adviser.lessons.each do |lesson| %>
5
7
  <% if lesson.votes.count.blank? %>
6
8
  <span class="top-like">
@@ -13,15 +15,15 @@
13
15
  <% end %>
14
16
  ```
15
17
 
16
- 色々tryしましたが、うまくいきません。
17
18
  ```ruby
18
19
  #application_helper.rb
19
20
 
20
21
  def vote_count(lesson)
21
- if lesson.votes.present?
22
+ if lesson.votes.blank?
23
+ content_tag(:span, content_tag(:i, "", class: "fa fa-heart-o", "aria-hidden" => "true"), class: "top-like")
24
+ else
22
- lesson.votes.count
25
+ count = lesson.votes.count
26
+ content_tag(:span, content_tag(:i, count, class: "fa fa-heart"), class: "top-like")
23
- elsif
27
+ end
24
28
  end
25
- end
26
-
27
29
  ```