【问题标题】:Ruby on Rails redirect_to with own params/values带有自己的参数/值的 Ruby on Rails redirect_to
【发布时间】:2012-12-15 11:43:37
【问题描述】:

我有一个非常相似的问题: Rails redirect_to with params

所以,我从这个线程中了解到,我可以像这样将参数添加到控制器 redirect_to:

format.html { redirect_to @order, :test => "test", notice: 'Order was successfully created.' }

据我了解,有了这个,我应该能够在视图中显示 :test 的值。 但是如果我尝试像这样访问它

<p>
  <b>Zahlungsart:</b>
   <%= params[:test] %>
</p>

什么都没有发生。

而且它似乎不是参数的一部分原因

<%= params.inspect %>

只是显示

{"action"=>"show", "controller"=>"orders", "id"=>"32"} 

我不知道这里到底出了什么问题.... redirect_to 就是那个,默认情况下由控制器的“创建”操作调用。

到目前为止,我通过定义 $test 来解决这个问题,在视图中可以使用 &lt;%= $test %&gt; 访问...但这对我来说似乎很丑(不是吗???)。

为了清楚起见,我想传递给视图的参数不是像控制器默认定义中的@order 这样的类的实例。它只是一个带有我想传递给视图的值的变量。 什么是正常的(RESTful

提前感谢您再次启发我 ;-)

问候

托比

【问题讨论】:

    标签: rest redirect ruby-on-rails-3.2 httprequest


    【解决方案1】:

    你应该这样使用它

    format.html { redirect_to order_path(@order, :test => "test"), notice: 'Order was successfully created.' }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多