2

我的控制器文件如下所示:

class QuotesController < ApplicationController

  def show
    @quote = Quote.find(params[:id])
    @popup = params[:popup]

    respond_to do |format|
      if @popup.present?
        format.html { render layout: false }
      else
        format.html
      end
      format.json { render json: @quote }
    end
  end

  def create    
    @quote = Quote.new(params[:quote])
    respond_to do |format|
      if @quote.save
        format.html { redirect_to @quote, notice: "Quote was successfully created.", popup: "1" }
        format.json { render json: @quote, status: :created, location: @quote }
      else
        format.html { render action: "errors", layout: false }
        format.json { render json: @quote.errors, status: :unprocessable_entity }
      end
    end
  end

end

如果我访问http://localhost:3000/quotes/1?popup=1 - 视图正确显示而没有 application_layout

但是,如果我来自 CREATE 操作,似乎 ?popup=1 永远不会附加到 URL - 因此 application_layout 在不应该显示的时候显示

我认为将 popup: "1" 添加到 redirect_to 行应该通过 GET 传递一个参数

谁能看到我错过了什么?

谢谢

4

2 回答 2

0

编辑:在我的机器上试过这个并且它有效:

{ redirect_to quote_path(@quote, :popup => "1"), notice: "Quote was successfully created." }

于 2012-04-08T01:36:39.940 回答
0

试试@quote_url(:popup=>1)吧,我想它会起作用的。

于 2012-04-08T04:37:44.360 回答