2012-03-16 31 views
1

我有一個處理聯繫人電子郵件的控制器。我有一個這樣的動作:Rails - 電子郵件控制器重定向混淆

def representative 
    @contact = UserContact.new() 
    if request.method == 'POST' 
    @contact = UserContact.new(params[:merchant_contact]) 
    if @contact.valid? 
     @contact.contact_email = current_user.email 
     @contact.contact_phone = current_user.phone_number 
     Emailer.representative_contact(@contact, representative).deliver # sends the email 
      redirect_to **????**, :flash => { :notice => "Thank you! Someone will get back to you shortly."} 
    else 
     render :representative 
    end 
    else 
    render :representative 
    end 
end 

我呼籲來自不同地方contact_representative_path在我的代碼,我想的是,提交後重定向到用戶點擊contact_representative_path。我已經嘗試過:回來,但它只是呈現代表性觀點。

回答

0

redirect_to和return不會結束請求,爲了結束請求,您需要在結尾處添加return。

嘗試redirect_to contact_representative_path,:flash => { :notice => "Thank you! Someone will get back to you shortly."} and return

UPDATE

在會議散列,你可以存儲請求的URL,這將是跨越多個請求可用。 session[:return_to] ||= request.referer 然後調用redirect_to session[:return_to], :flash => { :notice => "Thank you! Someone will get back to you shortly."}

檢查this question,希望這能解決您的問題。

+0

那不能回答我的問題。我想從我來自的地方回來。你的建議總是會重定向到contact_representative_path。 – 2012-03-16 19:49:36

+0

我想我已經錯過了你的問題的最後部分,編輯我的答案。 – asitmoharna 2012-03-17 03:25:31