[英]redirect on rails to edit_user_path(current_user)
I am using stripe on my app and after someone puts in their info I want the page to redirect for them to edit their profile, which is edit_user_path(current_user)
我在应用程序上使用条纹,当有人输入他们的信息后,我希望页面重定向以供他们编辑其个人资料,即
edit_user_path(current_user)
How would I trigger a redirect after a few seconds to that page? 几秒钟后,如何触发重定向到该页面?
I was thinking about the javascript below but how would I make the URL the user edit path? 我在考虑下面的JavaScript,但是如何使URL成为用户编辑路径?
<script>
$(document).ready(function () {
// Handler for .ready() called.
window.setTimeout(function () {
location.href = "https://www.google.co.in";
}, 5000);
});
</script>
While rendering your view on the server side, you need to export the edit_user_path(current_user)
from ruby context to javascript context. 在服务器端渲染视图时,需要将ruby上下文中的
edit_user_path(current_user)
导出到javascript上下文中。
There are several ways to export data from ruby to javascript. 有几种方法可以将数据从ruby导出到javascript。 One of the approaches is to use
javascript_tag
and you could assign to a javascript variable as follows (just an example): 一种方法是使用
javascript_tag
,您可以按以下方式分配javascript变量(仅作为示例):
<%= javascript_tag do %>
window.edit_current_user_path = '<%= edit_user_path(current_user) %>'
<% end %>
Then you could use that variable in your javascript: 然后,您可以在JavaScript中使用该变量:
<script>
$(document).ready(function () {
// Handler for .ready() called.
window.setTimeout(function () {
location.href = window.edit_current_user_path;
}, 5000);
});
</script>
Refer to JavaScriptHelper#javascript_tag for more info: 有关更多信息,请参考JavaScriptHelper#javascript_tag :
You could make a hidden element with a data attribute in rails. 您可以在rails中创建一个带有data属性的隐藏元素。 Then read that tag from jquery.
然后从jquery读取该标签。
<div class='thing' data-thing='<%=edit_user_path(current_user)%>' style='display:none;'></div>
$(document).ready(function () {
$('.thing').attr("data-thing"); //path
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.