2012-03-30 20 views
2

我想調用集合的輔助方法,選擇其中接收的名稱,並執行一些操作,並返回該輸出如何調用helper方法在collection_select標籤

<%= collection_select :cust_alert,:alert_id, @alerts, :id, :name,:prompt => true %> 

和幫助我的方法是

def show_alert_name 
@name = @alerts.collect{|alert| alert.name.html_safe } 

end 

我需要做什麼樣的改變,我在這裏傳遞對象數組,所以我不能使用select標籤。或者是有任何其他方式做到這一點同樣的工作

+0

它是什麼,你想實現什麼呢? – 2012-03-30 07:13:48

+1

我想在我的collection_select中調用這個show_alert_name方法,這樣我就可以從我的字符串中刪除特殊字符 – SSP 2012-03-30 07:31:48

+0

啊,我用'inject'將'collect'混淆了一會兒。那麼,到目前爲止你嘗試過了什麼? – 2012-03-30 07:34:48

回答

1

我想這是你想要什麼:

<%= select :cust_alert, 
      :alert_id, 
      @alerts.map { |alert| [alert.name.html_safe, alert.id] }, 
      {:prompt => true} %> 
相關問題