2013-03-13 20 views
1

我一直想在後期的時候用#{variable}Rails的 - 通過可變閃光燈通知

被創建,但我必須失去了一些東西,因爲我收到的唯一消息是出現在閃光燈的通知中加一個變量「# {變量}」。

這是我的控制器:

def create 

    @participant = Participant.new(params[:participant]) 

    respond_to do |format| 
     if @participant.save 
     mail = params[:email] 
     format.html { redirect_to @participant, notice: 'Thanks, We will be sending out instructions to: #{mail}' } 
     format.json { render json: @participant, status: :created, location: @participant } 
     else 
     format.html { render action: "new" } 
     format.json { render json: @participant.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

我一直在試圖與@participants可變藏漢了,不過,我沒有得到任何東西,但實際的「#{@參與者}」在郵件中。

回答

5

我猜您填寫的郵件參與者表格,以便嘗試使用:

email = params[:participant][:mail] 

,並與""代替''

+0

啊,這是的 「」,而不是 '' ---- =)謝謝 – Philip 2013-03-13 10:17:32

+0

沒問題,是嗎?很高興我可以幫助:) – Zippie 2013-03-13 10:18:24

+0

是的,它是=)而只是參數[:電子郵件]沒有工作,但@參與者。電子郵件沒有=) – Philip 2013-03-13 10:29:02

3

您需要用雙引號代替單引號的字符串寫入。

Double quotes actually allow string interpolation。這是你想要的。

所以寫:

format.html { redirect_to @participant, notice: "Thanks, We will be sending out instructions to: #{mail}" } 
+0

是的,我知道它只能用雙引號完成,但我仍然不知道原因,並感謝您的幫助,這真的幫助我找到了答案! – ksugiarto 2013-03-13 11:33:14