1

我有一个处理联系电子邮件的控制器。我有这样的动作:

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的位置之后。我尝试过使用 :back,但它只是呈现了代表性视图。

4

1 回答 1

0

redirect_to 和 return 不会结束请求,为了结束请求,您需要在末尾添加 return。

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

更新

在会话哈希中,您可以存储在多个请求中可用的请求 url。 session[:return_to] ||= request.referer 然后打电话redirect_to session[:return_to], :flash => { :notice => "Thank you! Someone will get back to you shortly."}

检查这个问题,希望这能解决你的问题。

于 2012-03-16T19:35:53.693 回答