跨控制器操作共享数据
我有一个 Controller X,它基本上有 3 个新操作:搜索和结果。
新操作显示表单并具有一个搜索按钮,该按钮将参数 POST 到搜索操作。
搜索操作调用一些 ruby 方法来获取数据,并且需要将其传递给将显示数据的结果控制器。
从搜索操作中,我使用 redirect_to '/x/result', :some_data =>; @data
但我从未将 @data
作为结果视图中参数的一部分。
我正在使用 Rails 3.1
I have a Controller X which basically has 3 actions new, search and result.
new action displays the form and has a search button which POST the params to the search action.
Search action calls some ruby methods to get the data and that needs to be passed to result controller which will display the data.
from search action I'm using redirect_to '/x/result', :some_data => @data
But I never get @data
as part of my params in my result view.
I'm using Rails 3.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
redirect_to 是一个 HTTP 操作,它会告诉浏览器转到其他地方。您只能保留会话变量。您应该在搜索操作中显示,因为这是您查找数据的地方。
redirect_to is an HTTP action, it will tell the browser to go elsewhere. You can only keep session variables. You should display in your search action since that is where you lookup the data.