【问题标题】:Getting AbstractController::DoubleRenderError:获取 AbstractController::DoubleRenderError:
【发布时间】:2014-07-02 22:53:58
【问题描述】:
def purchase
 ...
 perform_payment_post
 redirect_to :action => 'billing'
 ...
end

  def perform_payment_post
    params[:coverages] ||= {}      
    params[:customer][:coverage_addon] = (params[:coverages].collect { |k,v| k }).join(', ')
    params[:customer][:coverage_ends_at] = 1.year.from_now
    Rails.logger.info("--- id = #{cookies.signed[:incomplete_gaq_customer_id]}")
    id = cookies.signed[:incomplete_gaq_customer_id]
    return redirect_to :action => @is_affiliate_user ? 'affiliate':'quote' if id.nil?
    @customer = Customer.find(cookies.signed[:incomplete_gaq_customer_id])
    return redirect_to :action => 'please_call' if @customer.status_id != 0
    @customer.update_attributes(params[:customer])
    @customer.notes.create({ :notes_text => @note }) if @note
    if params[:property_id].to_i == 0 then @customer.properties.create(params[:property]) end
  end

redirect_to :action => "billing" 线上的购买方法出现错误。

AbstractController::DoubleRenderError: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".

请帮帮我。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3


    【解决方案1】:

    如果你想在控制器中提前返回,你要么需要这样写

    redirect_to(:action => @is_affiliate_user ? 'affiliate':'quote') and return if id.nil?
    

    【讨论】:

      猜你喜欢
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多