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 に答える