我想在用户登录后运行一些 JavaScript 代码。
我使用此代码将用户重定向到他的个人资料。
def after_sign_in_path_for(resource)
profile_path
//call js code
end
有可能实现这个目标吗?
最佳答案
尝试下面的代码在登录后运行一些js代码:
def after_sign_in_path_for(resource)
session[:js_code] = true
profile_path
end
在个人资料 View 中
<script type="text/javascript">
$(document).ready(function(){
<% if session.has_key?(:js_code) %>
session.delete(:js_code)
// write your js code here
<% end%>
})
</script>
关于javascript - 用户在 Rails 5 中使用 Devise 登录后运行 JS 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45181620/