Ruby-on-rails redirect_to 与参数。如何将它们传递给我的视图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10724058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
redirect_to with params. How to pass them to my view?
提问by user1312490
I'm new with rails. I have used the redirect_towith paramsin my action, but now I don't know how to show these paramsto my view?
我是新来的导轨。我在我的行动中使用了redirect_towith params,但现在我不知道如何params在我的视图中显示这些?
回答by Kashiftufail
Try this variants:
试试这个变体:
redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'redirect_to thing_path(@thing, foo: params[:foo])
redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'redirect_to thing_path(@thing, foo: params[:foo])
Also, this link should be helpful for you.
此外,此链接应该对您有所帮助。
回答by thesis
Actually if you have sent something with redirect - you have passed it like GET params. In this case you can access them from your paramshash.
实际上,如果您通过重定向发送了一些东西 - 您已经像 GET params 一样传递了它。在这种情况下,您可以从params哈希中访问它们。
If you redirect like:
如果你像这样重定向:
redirect_to :controller => 'users', :action => 'edit', :id => 1, :param_a => 1, :param_b => 2
You have url like:
你有这样的网址:
http://localhost:3000/users/1/edit?param_a=1¶m_b=2
So you can access :param_aand :param_bin your view from params hash:
因此,您可以从 params 哈希访问:param_a和:param_b在您的视图中:
<%= params[:param_a] %>
<%= params[:param_b] %>

