ruby on rails redirect_to参数段不起作用

时间:2012-04-08 00:33:25

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

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

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传递一个参数

有人能看到我错过的东西吗?

由于

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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