我可以在 RoR 的视图中使用 redirect_to 吗? [英] Can I use redirect_to in a view in RoR?
问题描述
在我的应用程序中,每个页面上都会出现一个小框,用于检查用户发出的请求的状态.如果请求在任何时候被接受,那么用户应该自动被带到某个页面.到目前为止,这是我的代码:
In my app, I've got a little box that appears on every page, checking on the status of requests made by the user. If a request is accepted at any time, then the user should automatically be taken to a certain page. This is my code so far:
<% offersMade.each do |w| %>
<% if w.accepted == true %>
<% redirect_to offer_path(:email => "email@gmail.com") %>
<% end %>
<% end %>
但我收到此错误:
undefined method `redirect_to' for #<ActionView::Base:0x1042a9770>
不能在视图中使用 redirect_to 吗?如果没有,还有什么我可以使用的吗?感谢阅读.
Is it not possible to user redirect_to in a view? If not, is there something else I can use? Thanks for reading.
推荐答案
redirect_to 是 ActionController::Base Class 的一个方法,所以你不能在 ActionView 中使用它.
redirect_to is a method of ActionController::Base Class so you can not use it in ActionView.
您可以尝试以下
<% if w.accepted == true %>
<script type="text/javascript">
window.location.href="/logins/sign_up" // put your correct path in a string here
</script>
<% end %>
针对电子邮件参数进行了编辑
Edited for the email parameter
window.location.href="/logins/sign_up?email=<%= w.email %>"
抱歉,我不知道 ruby 中是否有相关内容.
Sorry i don't know if there is anything in ruby for that.
这篇关于我可以在 RoR 的视图中使用 redirect_to 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!