我可以在 RoR 的视图中使用 redirect_to 吗? [英] Can I use redirect_to in a view in RoR?

查看:41
本文介绍了我可以在 RoR 的视图中使用 redirect_to 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,每个页面上都会出现一个小框,用于检查用户发出的请求的状态.如果请求在任何时候被接受,那么用户应该自动被带到某个页面.到目前为止,这是我的代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆