gpt4 book ai didi

ruby-on-rails - 我可以在RoR的 View 中使用redirect_to吗?

转载 作者:行者123 更新时间:2023-12-03 12:24:16 25 4
gpt4 key购买 nike

在我的应用程序中,我在每个页面上都有一个小方框,用于检查用户发出的请求的状态。如果随时接受请求,则应自动将用户带到特定页面。到目前为止,这是我的代码:

 <% 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>

在 View 中不能使用redirect_to用户吗?如果没有,还有其他可以使用的东西吗?谢谢阅读。

最佳答案

redirect_to是ActionController::Base Class的方法,因此您不能在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 %>

编辑了电子邮件参数
window.location.href="/logins/sign_up?email=<%= w.email %>"

对不起,我不知道 ruby 有什么用。

关于ruby-on-rails - 我可以在RoR的 View 中使用redirect_to吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3170475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com