2017-07-17 96 views
2

我有以下的鋼軌幫手:助手不顯示任何

def prefixes_with_tip shops 
    capture do 
     shops.each do |s| 
     content_tag(:span,class: 'has-tip',title: s.name) do 
      concat s.prefix 
      Rails.logger.debug "TEST TEST TEST #{s.name} TEST TEST TEST TEST TEST TEST TEST " 
     end 
     end 
    end 
    end 

電話:

=prefixes_with_tip shop_list 

當它被稱爲在視圖中,我能看到的痕跡在控制檯中,但沒有在視圖中輸出。

這個幫手有什麼問題?

(Rails的4.2)

回答

2

問題是如何concat時,嘗試外content_tag使用它,像這樣:

def prefixes_with_tip shops 
    capture do 
    shops.each do |s| 
     concat content_tag(:span, s.prefix, class: 'has-tip',title: s.name) 
    end 
    end 
end 

注意,取出(否則concat韓元不起作用)並添加s.prefix作爲第二參數(其設置內容標籤)。

+0

讓我們想象我想再次迭代在p標籤內。我會怎麼做? – Syl

+0

也就是說,每個項目('s')都應該在'p'內的'span'中?例如:'

s.prefix

'。一些這樣的輸出? – Gerry